# ts-nkeys

> A public-key signature system based on Ed25519 for the NATS ecosystem in typescript for ts-nats and node-nats

Latest version **1.0.16** (published 2020-02-25) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install ts-nkeys
pnpm add ts-nkeys
yarn add ts-nkeys
bun add ts-nkeys
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.16 |
| Published | 2020-02-25 |
| First published | 2018-09-07 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 59.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | The NATS Authors |
| Maintainers | aricart |
| Keywords | nats, Ed25519, node, typescript |

## Links

- npm: https://www.npmjs.com/package/ts-nkeys
- Repository: https://github.com//nats-io/ts-nkeys
- npm.io page: https://npm.io/package/ts-nkeys

## Dependencies (1)

- [tweetnacl](https://npm.io/package/tweetnacl.md) ^1.0.3

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.16 (latest) — 2020-02-25
- 1.0.16-2 (next) — 2020-02-25
- 1.0.16-1 — 2020-02-25
- 1.0.14 — 2019-10-07
- 1.0.12 — 2019-03-22
- 1.0.10 — 2019-01-04
- 1.0.8 — 2018-12-07
- 1.0.4 — 2018-10-26
- 1.0.2 — 2018-10-25
- 1.0.1 — 2018-10-25
- 1.0.0 — 2018-10-25
- 0.9.0 — 2018-09-07

## README

# ts-nkeys


A public-key signature system based on Ed25519 for the [NATS ecosystem system](https://nats.io) in JavaScript and Typescript.

[![license](https://img.shields.io/github/license/nats-io/ts-nats.svg)](https://www.apache.org/licenses/LICENSE-2.0)
[![Build Status](https://travis-ci.org/nats-io/ts-nkeys.svg?branch=master)](https://travis-ci.org/nats-io/ts-nkeys)
[![Coveralls github branch](https://img.shields.io/coveralls/github/nats-io/ts-nkeys/master.svg)](https://coveralls.io/github/nats-io/ts-nkeys)
[![npm](https://img.shields.io/npm/v/ts-nkeys.svg)](https://www.npmjs.com/package/ts-nkeys)
[![npm](https://img.shields.io/npm/dt/ts-nkeys.svg)](https://www.npmjs.com/package/ts-nkeys)

ts-nkeys is a typescript nats library for node that for generating nkeys.

## Installation

```bash
npm install ts-nkeys
```

## Basic Usage

```typescript
    // create an user nkey - also possible to create accounts, clusters, servers.
    let user = createUser();

    // once you have an nkey you can generate various keys.
    // A seed is the public and private keys together.
    // Seeds are strings, and start with the letter 'S'. 
    // Seeds need to be kept safe and never shared.
    let seed = user.getSeed();
    t.true(Buffer.isBuffer(seed));
    t.is(seed[0], 'S'.charCodeAt(0));
    
    // the second letter in the seed represents its type:
    // `U` for user, 
    // `A` for account, 
    // `C` for cluster
    // `N` for severs
    t.is(seed[1], 'U'.charCodeAt(0));

    // public keys can be shared and can be used to verify signed content
    let publicKey = user.getPublicKey();
    t.true(Buffer.isBuffer(publicKey));
    // first letter represents the type of public key
    // `U` for user, 
    // `A` for account, 
    // `C` for cluster
    // `N` for severs
    t.is(publicKey[0], 'U'.charCodeAt(0));


    // To sign data
    let data = Buffer.from("HelloWorld");
    let sig = user.sign(data);
    
    // to verify use the user, public or seed:
    t.true(user.verify(data, sig));

    // public keys can be used to verify signatures you cannot sign with them though.
    let pk = fromPublic(publicKey);
    t.true(pk.verify(data, sig));

    // seeds can be used to reconstitute the keypair from a string
    let sk = fromSeed(seed);
    t.true(sk.verify(data, sig));
    // and can be used to sign
    let sig2 = sk.sign(data);
    t.true(sk.verify(data, sig));
```


## Supported Node Versions

Our support policy for Nodejs versions follows [Nodejs release support]( https://github.com/nodejs/Release).
We will support and build node-nats on even-numbered Nodejs versions that are current or in LTS.

## License

Unless otherwise noted, the NATS source files are distributed under the Apache Version 2.0 license found in the LICENSE file.

---
_Source: https://npm.io/package/ts-nkeys · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
