New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@arcblock/did-auth-storage

Package Overview
Dependencies
Maintainers
4
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arcblock/did-auth-storage

Storage interface for did-auth

1.7.1
latest
Source
npm
Version published
Weekly downloads
269
-19.46%
Maintainers
4
Weekly downloads
 
Created
Source

@arcblock/did-auth-storage

styled with prettier

Interface for define a storage class that can be used by [@arcblock/did-auth].

Table of Contents

Motivation & Spec

Since tokens are used everywhere make achieve better QR code experience, we should allow users to customize how to generate/store/update token records.

Basic APIs that a token storage should support:

  • async init(), optional, should be called before creating any instance, open a database connection, creating a embed database on file system
  • async create(token, status = created), create a new token record, persist in data store
  • async exist?(token, did), check for token existense
  • async read(token), read a token from database,
  • async update(token, updates), update token record
  • async delete(token), remove a token record
  • async gc(), optional, run garbage collection on the token storage

Plan to support:

  • token-storage-mongo
  • token-storage-psql
  • token-storage-nedb
  • token-storage-memory

Install

npm install @arcblock/did-auth-storage
// or
yarn add @arcblock/did-auth-storage

Usage

const StorageInterface = require('@arcblock/did-auth-storage');
const keystone = require('keystone');

module.exports = class KeystoneStorage extends StorageInterface {
  constructor() {
    this.model = keystone.list('LoginToken').model;
  }

  create(token, status = 'created') {
    const LoginToken = this.model;
    const item = new LoginToken({ token, status });
    return item.save();
  }

  read(token) {
    return this.model.findOne({ token });
  }

  update(token, updates) {
    return this.model.findOneAndUpdate({ token }, updates);
  }

  delete(token) {
    return this.model.remove({ token });
  }

  exist(token, did) {
    return this.model.findOne({ token, did });
  }
};

Contributors

NameWebsite
wangshijunhttps://ocap.arcblock.io

Keywords

forge

FAQs

Package last updated on 07 Sep 2022

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