šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

@bit-js/ncrypt

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bit-js/ncrypt

Fast node crypto utilities.

0.0.5
latest
npm
Version published
Maintainers
0
Created
Source

NCrypt

Fast node crypto utilities.

Signers

Signers are instances that can be used to sign and verify data.

// The data can be anything depending on the specific signer
interface Signer {
  sign: (data: string) => string;
  verify: (data: string, digest: string) => boolean;
}

KeyGrip

A fast drop-in replacement of the keygrip module.

import KeyGrip from "@bit-js/ncrypt/key-grip";

BasicSigner

A simple single key signer and verifier.

import BasicSigner from "@bit-js/ncrypt/basic-signer";

const signer = new BasicSigner("secret");

// Return the signed value
signer.sign(value);

// Return whether the hash matches the value
signer.verify(value, hash);

ValueSigner

Sign a value and verify it later.

import ValueSigner from "@bit-js/ncrypt/value-signer";

// Pass in a signer (choose one above) for signing and unsigning a value
const valueSigner = new ValueSigner(signer);

// Sign a value
const signedValue = valueSigner.sign("hi there"); // "hi there.[hash]"

// Get the original value if the hash matches, otherwise return null
const originalValue = valueSigner.unsign(signedValue); // "hi there"

Cookie utilities.

CookiePair

Use a cookie pair to send cookie

import { CookiePair } from "@bit-js/ncrypt/cookie";

// Initialize a cookie pair (key is required)
const pair = new CookiePair("id");

// Set the cookie value (optional)
pair.value = 0;

// Set a signer to sign the cookie value (optional)
pair.signer = signer;

// Set cookie expire date (optional)
pair.expires = new Date();

// Set cookie max age (optional)
pair.maxAge = 3600000;

// Whether cookie is accessible through client-side JS (optional)
pair.httpOnly = true;

// Indicates that the cookie should be stored using partitioned storage (optional)
pair.partitioned = true;

// Defines the host to which the cookie will be sent (optional)
pair.domain = domain;

// Indicates the path that must exist in the requested URL for the browser to send the header (optional)
pair.path = path;

// Indicates that the cookie is sent to the server only when a request is made with the https scheme (optional)
pair.secure = true;

// Controls whether or not a cookie is sent with cross-site requests (optional)
pair.sameSite = "Strict";

// Serialize the cookie to string
pair.serialize();

If the pair value is set to null, pair.serialize() will produce a cookie that lasts 0 second and only contains the domain and path if provided.

If you think this is a good idea then I guess ĀÆ_(惄)_/ĀÆ.

import { reactiveCookie, appendToHeaders } from "@bit-js/ncrypt/cookie";

// Create a Proxy over the original object
const cookie = reactiveCookie({});

// Every property is a cookie pair
const { id } = cookie;
id.value = 0;
id.sameSite = "Strict";

// Append all the pair values to a Headers object
appendToHeaders(new Headers(), cookie);

Keywords

crypto

FAQs

Package last updated on 11 Jul 2024

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