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

capitalisk-auth-server

v1.0.9

Published

A modular back end toolkit for easily implementing log in using any Capitalisk/LDPoS blockchain.

Downloads

3

Readme

capitalisk-auth-server

A modular back end toolkit for easily implementing log in using any Capitalisk/LDPoS blockchain.

What is this for?

This project provides back end Node.js components to allow you to easily extend your app or website to support authentication (log in) via a Capitalisk-based blockchain. It's an alternative to the standard email-based authentication which is currently supported by most websites and it saves you from having to do the work of setting up a registration page and handling the whole sign up and email verification flow.

This project is intended to be used with capitalisk-auth-client (https://github.com/Capitalisk/capitalisk-auth-client) on the front end to initiate the authentication flow. This library is highly versatile and can work with any transport protocol (I.e. HTTP/HTTPS and WebSockets) and any API framework on the back end (I.e. ExpressJS, Koa... or without any framework).

How does it work?

See https://github.com/Capitalisk/capitalisk-auth-client#how-does-it-work

Usage

Include library

const { CapitaliskAuthProvider, convertWalletAddressToId } = require('capitalisk-auth-server');

Or with import syntax:

import capitaliskAuthServer from 'capitalisk-auth-server';
const { CapitaliskAuthProvider, convertWalletAddressToId } = capitaliskAuthServer;

Instantiate CapitaliskAuthProvider

You should Instantiate it at the top level scope outside of any API route handlers like this:

let capitaliskAuth = new CapitaliskAuthProvider({
  hostname: 'capitalisk.com',
  port: 443,
  networkSymbol: 'clsk',
  chainModuleName: 'capitalisk_chain',
  secure: true,
  minAccountBalance: 1
});

Then, ideally somewhere near the top, inside your API endpoint handler/function:

// Assuming your API handler is an async function...

let walletInfo;
try {
  // Be sure to add the await keyword here to catch async errors.
  // The credentials object comes directly from the front end
  // capitalisk-log-in component's 'submitCredentials' event.detail property.
  walletInfo = await capitaliskAuth.authenticate(credentials);
} catch (error) {
  // The authenticate() method will throw an error if blockchain authentication
  // fails or if the credentials object format is incorrect.
  // In this case, respond to the request with an error.
  // ... RESPOND HERE.
  // Also, log the exception somewhere.
  // You can return from the function to prevent further processing.
  // Do not proceed with authentication.
  return;
}
// If no error was thrown, then it means authentication was successful and you
// can either create a session for your user and/or respond with a token (e.g. JWT).

let { walletAddress, accountBalance } = walletInfo;

// This optional utility function allows you to convert a blockchain wallet address
// into a valid UUIDv4 string deterministically derived from it.
// It can be useful for databases which support UUIDs and it allows you
// have a direct mapping between blockchain accounts and account IDs within your system.
let accountId = convertWalletAddressToId(walletAddress);

// ...