Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@tanker/identity

Package Overview
Dependencies
Maintainers
6
Versions
136
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tanker/identity

Tanker Identity SDK

Source
npmnpm
Version
2.0.2-alpha4
Version published
Weekly downloads
67
-69.27%
Maintainers
6
Weekly downloads
 
Created
Source

Identity SDK

Tanker Identity generation in JavaScript for the Tanker SDK.

Installation

The preferred way of using the component is via NPM:

npm install --save @tanker/identity

Usage

The server-side code below demonstrates a typical flow to safely deliver identities to your users:

import { createIdentity } from '@tanker/identity';

// Store these configurations in a safe place
const trustchainId = '<trustchain-id>';
const trustchainPrivateKey = '<trustchain-private-key>';

// Example server-side function in which you would implement checkAuth(),
// retrieveUserIdentity() and storeUserIdentity() to use your own authentication
// and data storage mechanisms:
async function getUserIdentity(userId) {
  const isAuthenticated = checkAuth(userId);

  // Always ensure user is authenticated before returning a user identity
  if (!isAuthenticated) {
    throw new Error('unauthorized');
  }

  // Retrieve a previously stored user identity for this user
  let identity = retrieveUserIdentity(userId);

  // If not found, create a new user identity
  if (!identity) {
    identity = await createIdentity(trustchainId, trustchainPrivateKey, userId);

    // Store the newly generated user identity
    storeUserIdentity(userId, identity);
  }

  // From now, the same user identity will always be returned to a given user
  return identity;
}

Read more about user identity in the Tanker guide.

FAQs

Package last updated on 12 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts