ts-nkeys
A public-key signature system based on Ed25519 for the NATS ecosystem in typescript for ts-nats and node-nats
Last updated 6 years ago by aricart .
Apache-2.0 · Repository · Original npm · Tarball · package.json
$ cnpm install ts-nkeys 
SYNC missed versions from official npm registry.

ts-nkeys

A public-key signature system based on Ed25519 for the NATS ecosystem system in JavaScript and Typescript.

license Build Status Coveralls github branch npm npm

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

Installation

npm install ts-nkeys

Basic Usage

    // 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. 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.

Current Tags

  • 1.0.16                                ...           latest (6 years ago)
  • 1.0.16-2                                ...           next (6 years ago)

12 Versions

  • 1.0.16                                ...           6 years ago
  • 1.0.16-2                                ...           6 years ago
  • 1.0.16-1                                ...           6 years ago
  • 1.0.14                                ...           7 years ago
  • 1.0.12                                ...           7 years ago
  • 1.0.10                                ...           7 years ago
  • 1.0.8                                ...           7 years ago
  • 1.0.4                                ...           7 years ago
  • 1.0.2                                ...           7 years ago
  • 1.0.1                                ...           7 years ago
  • 1.0.0                                ...           7 years ago
  • 0.9.0                                ...           8 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 4
Last Day 0
Last Week 4
Last Month 1
Dependencies (1)
Dev Dependencies (7)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |