Skip to main content

@std/crypto@0.215.0

latest
Works with
It is unknown whether this package works with Browsers, Deno, Node.js, Cloudflare Workers, Bun
It is unknown whether this package works with Browsers
It is unknown whether this package works with Deno
It is unknown whether this package works with Node.js
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score70%
Published2 years ago (0.215.0)
class KeyStack

A cryptographic key chain which allows signing of data to prevent tampering, but also allows for easy key rotation without needing to re-sign the data.

Data is signed as SHA256 HMAC.

This was inspired by keygrip.

Examples

Example 1

import { KeyStack } from "@std/crypto/unstable_keystack";

const keyStack = new KeyStack(["hello", "world"]);
const digest = await keyStack.sign("some data");

const rotatedStack = new KeyStack(["deno", "says", "hello", "world"]);
await rotatedStack.verify("some data", digest); // true

Constructors

new KeyStack(keys: Iterable<Key>)

A class which accepts an array of keys that are used to sign and verify data and allows easy key rotation without invalidation of previously signed data.

Properties

Number of keys

Methods

Custom output for Deno.inspect.

[Symbol.for("nodejs.util.inspect.custom")](
depth: number,
options: any,
inspect: (
value: unknown,
options?: unknown
) => string
): string

Custom output for Node's util.inspect.

Given data and a digest, return the current index of the key in the keys passed the constructor that was used to generate the digest. If no key can be found, the method returns -1.

Take data and return a SHA256 HMAC digest that uses the current 0 index of the keys passed to the constructor. This digest is in the form of a URL safe base64 encoded string.

Given data and a digest, verify that one of the keys provided the constructor was used to generate the digest. Returns true if one of the keys was used, otherwise false.

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/crypto

Import symbol

import { KeyStack } from "@std/crypto";
or

Import directly with a jsr specifier

import { KeyStack } from "jsr:@std/crypto";