bxxf / typed-secure-storage

LocalStorage wrapper with TypeScript autocompletion support and encryption

Home Page:https://www.npmjs.com/package/typed-secure-storage

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Typed Secure Storage

Typed Secure Storage is a utility for secure, encrypted storage in the browser with type definition schema. It is built on top of the Web Crypto API and Local Storage. It is designed to be simple to use and easy to integrate into existing projects.

Features

  • Type Definition Schema: Easily define the schema of the data you want to store and retrieve.
  • Encryption: Data is encrypted using the Web Crypto API using AES-GCM.

Installation

bun install typed-secure-storage

Usage

Here's how to quickly get started with typed-secure-storage:

  1. Define the schema
interface Todo {
  title: string;
  completed: boolean;
}

interface Schema {
  todos: Todo;
}
  1. Create a new instance of TypedSecureStorage
import { createTypedSecureStorage } from "typed-secure-storage";

const secretKey = "your-secret-key"; // Replace with your secret key
const salt = "your-salt"; // Replace with your salt

const storage = await createTypedSecureStorage<Schema>(secretKey, salt);
  1. Use the storage
const todo: Todo = {
  title: "Buy milk",
  completed: false,
};

// Save a single item
const res = await storage.set("todos", todo);
// Get a single item
const todo = await storage.get("todos", res.key);
console.log(todo.title); // "Buy milk"
// Get all items
storage.getAll("todos");
// Filter items
storage.filter("todos", (todo) => todo.completed);
// Remove a single item
storage.remove("todos", res.key);

Disclaimer

This project does not guarantee safety and security - all security-sensitive data and operations should not be handled in the client-side. This project is not responsible for any security breaches or data loss.

About

LocalStorage wrapper with TypeScript autocompletion support and encryption

https://www.npmjs.com/package/typed-secure-storage


Languages

Language:TypeScript 100.0%