NCrypt
Fast node crypto utilities.
Signers
Signers are instances that can be used to sign and verify data.
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");
signer.sign(value);
signer.verify(value, hash);
ValueSigner
Sign a value and verify it later.
import ValueSigner from "@bit-js/ncrypt/value-signer";
const valueSigner = new ValueSigner(signer);
const signedValue = valueSigner.sign("hi there");
const originalValue = valueSigner.unsign(signedValue);
Cookie
Cookie utilities.
CookiePair
Use a cookie pair to send cookie
import { CookiePair } from "@bit-js/ncrypt/cookie";
const pair = new CookiePair("id");
pair.value = 0;
pair.signer = signer;
pair.expires = new Date();
pair.maxAge = 3600000;
pair.httpOnly = true;
pair.partitioned = true;
pair.domain = domain;
pair.path = path;
pair.secure = true;
pair.sameSite = "Strict";
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.
Reactive cookie
If you think this is a good idea then I guess ĀÆ_(ć)_/ĀÆ.
import { reactiveCookie, appendToHeaders } from "@bit-js/ncrypt/cookie";
const cookie = reactiveCookie({});
const { id } = cookie;
id.value = 0;
id.sameSite = "Strict";
appendToHeaders(new Headers(), cookie);