npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

curve25519-node

v0.0.1

Published

This library isolates the implementation of the X25519 curves used in [libsignal-protocol-javascript](https://github.com/signalapp/libsignal-protocol-javascript) and exposes the basic functions in an easy to use TypeScript package.

Downloads

11

Readme

Typescript Library for Curve 25519

This library isolates the implementation of the X25519 curves used in libsignal-protocol-javascript and exposes the basic functions in an easy to use TypeScript package.

Installation

Use yarn to install:

yarn add @privacyresearch/curve25519-typescript

Then in your code simply import the class you want:

import { Curve25519Wrapper } from '@privacyresearch/curve25519-typescript'
// OR...
import { AsyncCurve25519Wrapper } from '@privacyresearch/curve25519-typescript'

We'll say more about the differences between the two curve wrappers below.

Usage

Before getting into the details, here's a quick example of a Diffie-Hellman key exchange (not that you would ever do both key computations in one place!):

const curve = await Curve25519Wrapper.create()

const alicePair = curve.keyPair(alice_bytes)
const bobPair = curve.keyPair(bob_bytes)

const aliceSecret = curve.sharedSecret(bobPair.pubKey, alicePair.privKey)
const bobSecret = curve.sharedSecret(alicePair.pubKey, bobPair.privKey)

Note the await! The curve wrapper is created asynchronously.

We can sign and verify too:

// pub, priv, msg are all ArrayBuffers
const curve = await Curve25519Wrapper.create()
const sig = curve.sign(priv, msg)
const verified = curve.verify(pub, msg, sig)
if (verified) {
  // Yes, this is correct.  `verify` returns `true` for invalid signatures
  throw new Error('INVALID SIGNATURE!')
}

Note the return value of verify! This is for compatibility with usage in libsignal-protocol-javascript. To avoid confusion, we offer an alternative:

const signatureIsValid = curve.signatureIsValid(pub, msg, sig)
if (!signatureIsValid) {
  throw new Error('INVALID SIGNATURE!')
}

That pretty much covers it, but look at the tests for details about creating ArrayBuffers for input and getting some sample data to get started.

Async or not Async?

In the installation instructions we noted that the package exports two classes: Curve25519Wrapper and AsyncCurve25519Wrapper. The examples above all use Curve25519Wrapper. Here are the differences between the two:

Wrapper creation

As seen in the examples above Curve25519Wrapper must be created asynchronously, but all of its methods are synchronous.

On the other hand AsyncCurve25519Wrapper can be instantiated synchronously, but all of its methods are async. For example, here his how message signing looks with this wrapper:

// Just create the wrapper, no need to await it
const curve = new AsyncCurve25519Wrapper()

// but now curve.sign returns a Promise<ArrayBuffer>!
const sigCalc = await curve.sign(priv, msg)

Building

The core curve implementation is written in C and can be found in the native/ directory. It is compiled to Javascript with Emscripten and the compilation command can be seen in compile.sh.

If you want to make modifications to the C code or change compilation arguments (e.g. to optimize more aggressively), you will need to install Emscripten.

Thanks!

This is really just a direct lift of work done by the folks at Signal so that we can use it easily in our TypeScript projects. Thanks to them for putting the core of this together!

License

Copyright 2020 Privacy Research, LLC

Licensed under the GPLv3: http://www.gnu.org/licenses/gpl-3.0.html