npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@synonymdev/slashauth

v1.0.0-alpha.0

Published

Authorization using slashtags

Downloads

9

Readme

SlashAuth

SlashAuth is a Slashtags protocol for authorization over a Slashtag's connection.

Once authentication is done both sides share a private encrypted drives dedicated to each other, and can exchange data over, as an asynchronous communication channel.

Install

npm i @synonymdev/slashtag @synonymdev/slashauth

Usage

Initiator's side

import { Slashtag } from '@synonymdev/slashtag';
import { SlashAuth } from '@synonymdev/slashauth';

const initiator = new Slashtag({
  keyPair: Slashtag.createKeyPair(),
  protocols: { SlashAuth },
});
// Responder's wallet will have access to the initiator's profile
await initiator.setProfile({ name: 'Alice' });
// Access the protocol instance from anywhere in the application
const auth = slashtag.protocol(SlashAuth);

// After getting the slashauth:// url from the Responder,
// you can use it to read the Responder's profile
const responder = sdk.slashtag({ url: slashauthURL });
// Get the server's profile if it exists, so you can ask
// user for confirmation to authenticate to that Responder
const profile = await serverSlashtag.getProfile();

auth.once('error', errorHandler);

// On success, Initiator will get the details of the Drive that
// the Responder created for the Initiator
auth.once('success', ({ drive }) => {
  // Success handler
});

// Connect to the server and send the token in the url `?q=<token>`
auth.request(url);

Responder's side

import { Slashtag } from '@synonymdev/slashtag';
import { SlashAuth } from '@synonymdev/slashauth';

const responder = new Slashtag({
  keyPair: Slashtag.createKeyPair(),
  protocols: { SlashAuth },
});
// Initiator's wallet will have access to the Responder's profile
await responder.setProfile({ name: 'Bob' });
const auth = slashtag.protocol(SlashAuth);

auth.on('request', async ({ token, peerInfo, drive }, response) => {
  // Try resolving user's profile from their Slashtag
  const initiator = request.peerInfo.slashtag;

  // The Responder can send either a success or error message
  try {
    authorize(request.token, initiator);
    response.success();
  } catch (e) {
    response.error(e.message);
  }
});

// Listen on the Slashtag.key
await slashtag.listen();

function authorize(token, initiator) {
  // Check the token against server's sessions, clientIDs, etc.
  // Check if the user is already registered, blocked, etc.
}

// Generate a slashauth:// url and pass it to the initiator
// token can be a random string, or a session token or a clientID, etc.
SlashAuth.formatURL(slashtag.url, token);

How it works

Before any of the SlashAuth's messages are exchanged, the Initiator and Responder are already connected over a secure connection using Noise Protocol.

More about Slashtags connections here.

So both the Initiator's and Responder's keys are already known and all subsequent communication is trusted.

This protocol adds two features:

  1. The Initiator can pass a session token to the Responder.
  2. Both the Initiator and the Responder creates a dedicated drive for each other. Enabling further asynchronous communication between both parties.

Examples

Contacts

Initiator 'Alice' wants to establish a connection to Responder 'Bob'.

  • Bob creates a url with the protocol slashauth:, Bob's base32 encoding publicKey, and a unique token for this session.
  • Alice connects to Bob using the Bob's publicKey parsed from the url, and pass the token, as well as the publicKey and encryptionKey to the drive created by Alice for Bob.
  • If Bob accepts the request, Bob creates a drive dedicated for Alice, and sends it back to Alice.
  • If Bob rejects the request, Bob can send an error message to Alice.

Once the request is accepted, now both Alice and Bob add each other as contacts, with drives for Incoming and Outgoing asynchronous messages.

simple p2p authentication protocol diagram

Login & Registration

  • Initiator 'Alice' visits a website, which can be a login page, or a 3rd party client.
  • The client formats a url from the Server's publicKey, and a unique token to that client, whether that is a session token or a clientID, etc. That is left to the each application to decide.
  • Alice connects to the server using its publicKey, and passes the token, and the dedicated drive.
  • If the Server accepts the request, Alice will now get the details of the Server's drive, and the Server can now authorize the Client to request resources.

server, clietn, and wallet authentication diagram