JSPM

edkeys

0.1.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q17170F
  • License MIT

Node.js library for ed25519 keys management

Package Exports

  • edkeys
  • edkeys/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (edkeys) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

edkeys

Node.js library for ed25519 keys management.

npm i edkeys

By default it saves the files in ~/.hyperkeys.

Usage

const Hyperkeys = require('edkeys')

const hyperkeys = new Hyperkeys()

const seed = hyperkeys.create(name)
const { publicKey, secretKey, seedKey } = hyperkeys.get(name)

hyperkeys.set(name, { publicKey, secretKey, seedKey })

const paths = hyperkeys.exists(name)

hyperkeys.remove(name)

const { keyPairs, knownKeys } = hyperkeys.list()

Hyperkeys.keyTriad() // => { publicKey, secretKey, seedKey }

Dir

const hyperkeys = new Hyperkeys({ dir: '/home/user/.another-folder' })

Global dir

Hyperkeys.dir = '/home/user/.global-folder'

// Now all instances uses that global directory
const hyperkeys1 = new Hyperkeys()

// Setting a specific dir overrides the global
const hyperkeys2 = new Hyperkeys({ dir: '/home/user/.override-folder' })

Create

// Writes the file to disk: ~/.hyperkeys/crst
const seedKey = hyperkeys.create('crst')

If you try to create twice with the same name it will throw an error.

Get

If you have the seedKey then it will return all the keys.
That's because you can derivate the public and secret keys from the seed.

const keys = hyperkeys.get('crst')
// => { publicKey, secretKey, seedKey }

If you only have the publicKey then that's what you'll get.

const keys = hyperkeys.get('friend')
// => { publicKey, secretKey: null, seedKey: null }

Set

You can force to save any key to a specific name.

hyperkeys.set('friend', { publicKey: Buffer<newer public key> })

Another example:

// As previously said, this will save only the seedKey to disk
hyperkeys.create('vm1')

// You can use "get" to retrieve and generate all the corresponding keys
const keys = hyperkeys.get('vm1')

// And force save them
hyperkeys.set('vm1', keys)

// Now you have those files saved:
// publicKey: ~/.hyperkeys/vm1.pub
// secretKey: ~/.hyperkeys/vm1.sec
// seedKey: ~/.hyperkeys/vm1

Exists

It will return the keys filepath linked to the name.

hyperkeys.create('vm2')
const exists = hyperkeys.exists('vm2')
// => { publicKey: null, secretKey: null, seedKey: '/home/user/...' }
// Again, with this we have explicitly all the keys in disk
hyperkeys.create('vm3')
hyperkeys.set('vm3', hyperkeys.get('vm3'))

const exists = hyperkeys.exists('vm3')
// => { publicKey: '/home/user/...', secretKey: '/home/user/...', seedKey: '/home/user/...' }
const exists = hyperkeys.exists('non-existent')
// => { publicKey: null, secretKey: null, seedKey: null }

Remove

It will remove all the keys, be it publicKey, secretKey and/or seedKey.

hyperkeys.remove('vm1')

List

keyPairs is when you have the seedKey or combination of publicKey and secretKey.
knownKeys are the keys where you don't have either the secretKey and seedKey.

const { keyPairs, knownKeys } = hyperkeys.list()
// keyPairs => [{ name, publicKey, secretKey, seedKey }, ...]
// knownKeys => [{ name, publicKey, secretKey: null, seedKey: null }, ...]

Note: If you only have the secretKey file (.sec) it will not show up on the list.
It may be possible to derive the publicKey from the secretKey but not done for now.

keyTriad (static)

const keyTriad = Hyperkeys.keyTriad()
// => { publicKey, secretKey, seedKey }

keyPair (static)

const keyPair = Hyperkeys.keyPair()
// => { publicKey, secretKey }

seed (static)

const seed = Hyperkeys.seed()
// => Buffer<32 random bytes>

License

MIT