Charm implementation in JavaScript (TypeScript)

Overview

charm.js

A tiny, self-contained cryptography library, implementing authenticated encryption and keyed hashing.

Any number of hashing and authenticated encryption operations can be freely chained using a single rolling state. In this mode, each authentication tag authenticates the whole transcript since the beginning of the session.

This is a port to JavaScript (TypeScript). It is fully compatible with the C and Zig versions.

Usage

Initialization

A state must be initialize using a key, and an optional nonce. The nonce is not required is a key is used only once per session.

import { Charm } from "@jedisct1/charm";
import crypto from "crypto";

const key = new Uint8Array(Charm.key_length);
crypto.getRandomValues(key);
let st = new Charm(key);

The key size is Charm.key_length bytes long, and the nonce size Charm.nonce_length bytes long. The nonce can be provided as a second parameter of the constructor.

Once initialized, the state can be used for any encryption/decryption/hashing sequence. Every output depends on the previous input, hence authenticating the entire session.

Encryption

const x1 = new Uint8Array([0, 1, 2, 3, 4]);
const tag1 = st.encrypt(x1);

const x2 = new Uint8Array([5, 6, 7]);
const tag2 = st.encrypt(x2);

The encrypt() function encrypts a message in-place, and returns the authentication tag.

Decryption

Decryption must happen within the same state as encryption:

st = new Charm(key);
st.decrypt(x1, tag1);
st.decrypt(x2, tag2);

An exception is thrown if the tag doesn't verify.

Hashing

const x3 = new Uint8Array([8, 9, 10, 11, 12, 13, 14, 15])
const h = st.hash(x3);

Security guarantees

128-bit security, no practical limits on the size and length of messages.

Other implementations:

  • charm original implementation in C.
  • zig-charm an implementation of Charm in the Zig language.
You might also like...

javascript implementation of logistic regression/c4.5 decision tree

LearningJS: A Javascript Implementation of Logistic Regression and C4.5 Decision Tree Algorithms Author: Yandong Liu. Email: yandongl @ cs.cmu.edu Upd

Aug 19, 2022

ParkyDB - block based, linkable and verifiable document database -- javascript reference implementation

ParkyDB - block based, linkable and verifiable document database -- javascript reference implementation

Ancon ParkyDB A data mesh database using Web 3.0 technology Note: Requires Node v17.7.2 and up for development More about data mesh architecture Block

Aug 16, 2022

An implementation of (Untyped) Lambda Calculus in JavaScript.

Lambda Calculus More restraint and more pure, so functional and so reduced. -- Anonymous Bauhaus Student An implementation of (Untyped) Lambda Calculu

Nov 17, 2022

An implementation of Interaction Nets in JavaScript.

Interaction Nets An implementation of Interaction Nets in JavaScript. Use S-expression as overall syntax. Use Forth-like postfix stack-based syntax to

Dec 23, 2022

An Open-Source JavaScript Implementation of Bionic Reading.

bionic-reading Try on Runkit or Online Sandbox An Open-Source JavaScript Implementation of Bionic Reading API. ⚙️ Install npm i bionic-reading yarn ad

Dec 16, 2022

A tiny CRDT implementation in Javascript.

Tiny Merge A tiny CRDT implemented in Javascript. The philosophy behind Tiny Merge is to strategically reduce the functionality of CRDT's in favour of

Dec 2, 2022

An Open-Source JavaScript Implementation of Bionic Reading.

An Open-Source JavaScript Implementation of Bionic Reading.

TextVide (vide; Latin for "see") Support all languages that separate words with spaces Try on Runkit or Online Sandbox An Open-Source JavaScript Imple

Dec 16, 2022

A JavaScript implementation of the Spring 83 protocol

An implementation of the Spring 83 protocol. Very much a work-in-progress. This was built in reference to draft-20220616.md@0f63d3d2. Setup Requires n

Aug 22, 2022

A native-like JavaScript pull to refresh implementation for the web.

Pull to Refresh for the Web 1.1 This is a pull to refresh implementation for the web. It focuses on buttery UX performance and responsiveness to feel

Dec 19, 2022
Owner
Frank Denis
Get my public keys here: https://sk.tl/7CPRo8kn
Frank Denis
🐬 A simplified implementation of TypeScript's type system written in TypeScript's type system

?? HypeScript Introduction This is a simplified implementation of TypeScript's type system that's written in TypeScript's type annotations. This means

Ronen Amiel 1.8k Dec 20, 2022
Implementation of original Lisp as described in Paul Graham's article "The Roots of Lisp". In Typescript

Roots of Lisp This is the implementation of original Lisp from 1960 as described in Paul Graham's article How to use Building If you just want to run

Serhii Dolia 7 Oct 28, 2022
A TypeScript implementation of High-Performance Polynomial Root Finding for Graphics (Yuksel 2022)

Nomial Nomial is a TypeScript implementation of Cem Yuksel's extremely fast, robust, and simple root finding algorithm presented in the paper "High-Pe

Peter Boyer 10 Aug 3, 2022
An implementation of Saudi Arabia ZATCA's E-Invoicing requirements, processes, and standards in TypeScript.

v0.1.0 (experimental) An implementation of Saudi Arabia ZATCA's E-Invoicing requirements, processes, and standards in TypeScript. Read the documentati

wes4m 32 Dec 27, 2022
Typescript implementation of the shopif-app-template-node

Shopify App Template - Node This is a template for building a Shopify app using Node and React. It contains the basics for building a Shopify app. Rat

Kai Spencer 9 Dec 21, 2022
Simple Library implemented using HTML, CSS and JavaScript. This is a simple implementation of JavaScript Modules of ES6.

Awesome-books A single page project with the porpuse of storing books' titles and authors. Built With CSS, HTML & Javascript. How to run in your local

Saadat Ali 7 Feb 21, 2022
Javascript implementation of flasher tool for Espressif chips, running in web browser using WebSerial.

Javascript implementation of esptool This repository contains a Javascript implementation of esptool, a serial flasher utility for Espressif chips. Un

Espressif Systems 103 Dec 22, 2022
A JavaScript implementation of Michael Baker's Miner2149

miner2149-js A JavaScript implementation of Michael Baker's Miner2149. This repository is for personal use only. Not for commercial use or distributio

Gabrien Symons 1 Jan 11, 2022
A fast simplex noise implementation in Javascript.

simplex-noise.js API Documentation simplex-noise.js is a simplex noise implementation in Javascript/TypeScript. It works in the browser and nodejs. Us

Jonas Wagner 1.2k Jan 2, 2023
A javascript text differencing implementation.

jsdiff A javascript text differencing implementation. Based on the algorithm proposed in "An O(ND) Difference Algorithm and its Variations" (Myers, 19

Kevin Decker 6.8k Jan 7, 2023