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

@lowlighter/crypto

v1.1.6

Published

Features based upon Web Crypto APIs

Downloads

240

Readme

🧮 Cryptographic utilities

JSR JSR Score NPM Coverage

🔑 Time-based One-Time Password (TOTP)

Issue a new TOTP secret with metadata (issuer, account, image, etc.).

📑 Examples

import { otpauth, otpsecret, verify } from "./totp.ts"
import { qrcode } from "../qrcode/mod.ts"

// Issue a new TOTP secret
const secret = otpsecret()
const url = otpauth({ issuer: "example.com", account: "alice", secret })
console.log(`Please scan the following QR Code:`)
qrcode(url.href, { output: "console" })

// Verify a TOTP token
const token = prompt("Please enter the token generated by your app:")!
console.assert(await verify({ token, secret }))

✨ Features

  • Has no external dependencies.
  • Is lightweight.

This library is based on the well-written article of @rajat-sr How To Implement Google Authenticator Two Factor Auth in JavaScript

🔐 Symmetric encryption (using AES-GCM 256 with a PBKDF2 derived key)

📑 Examples

import { decrypt, encrypt, exportKey, importKey } from "./encryption.ts"

// Generate a key. Same seed and salt combination will always yield the same key
const key = await exportKey({ seed: "hello", salt: "world" })
console.assert(key === "664d43091e7905723fc92a4c38f58e9aeff6d822488eb07d6b11bcfc2468f48a")

// Encrypt a message
const message = "🍱 bento"
const secret = await encrypt(message, { key, length: 512 })
console.assert(secret !== message)

// Encrypted messages are different each time and can also obfuscate the original message size
console.assert(secret !== await encrypt(message, { key, length: 512 }))
console.assert(secret.length === 512)

// Decrypt a message
const decrypted = await decrypt(secret, { key })
console.assert(decrypted === message)

✨ Features

  • Use the native Web Crypto APIs.
  • Uses a AES-GCM 256-bits with PBKDF2-derived key to encrypt and decrypt messages.
    • Encrypted messages are different each time thanks to an initialization vector.
    • The derived keys from a given seed/password are always the same.
  • Includes functionalities to introduce additional entropy:
    • Support for SHA-256 to guarantee integrity.
    • Support for retaining the stored size to help verify integrity (for messages with length < 255)
    • Support for adding padding to force length be 256 or 512 bytes and obfuscate the original size (can be disabled using 0 as value)

📜 License and credits

Copyright (c) Simon Lecoq <@lowlighter>. (MIT License)
https://github.com/lowlighter/libs/blob/main/LICENSE

[!CAUTION]

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND

The author is not responsible for any damage that could be caused by the use of this library. It is your responsibility to use it properly and to understand the security implications of the choices you make.