1.1.1 • Published 1 month ago

@asanrom/dilithium v1.1.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 month ago

CRYSTALS-Dilithium (Javascript implementation)

npm version

Javascript implementation of post-quantum signature algorithm: CRYSTALS-Dilithium.

Note: This is an experimental implementation. I do not recommend using it in production until the algorithm is standarized.

Installation

If you are using a npm managed project use:

npm install @asanrom/dilithium

If you are using it in the browser, download the minified file from the Releases section and import it to your html:

<script type="text/javascript" src="/path/to/dilithium.js"></script>

The browser library exports all artifacts to the window global: DilithiumAlgorithm

Usage

import { DilithiumKeyPair, DilithiumLevel, DilithiumLevelNumber, DilithiumSignature } from "@asanrom/dilithium";

const level = DilithiumLevel.get(2); // Get the security level config (2, 3, or 5)

// Generate a key pair
const keyPair = DilithiumKeyPair.generate(level);

// Get the private key
const privateKey = keyPair.getPrivateKey();

// Sign a message
const message = new Uint8Array(Buffer.from("Joy!", "utf8"));
const signature = privateKey.sign(message);

// Get the public key
const publicKey = keyPair.getPublicKey();

// Validate signature
const valid = publicKey.verifySignature(message, signature);

Documentation