1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-11-22 09:46:58 +01:00
js-bigchaindb-driver/src/Ed25519Keypair.js
Matthias Kretschmann 81ef5978b8
API docs & dev updates
* new command: npm run doc, for generating the API.md file
* new command: npm run dev, for live watching webpack
* JSdoc: make all methods public by default, selectively make some private
* JSdoc: organize all methods under their class
* linting fixes
* package updates
2018-05-14 17:14:40 +02:00

18 lines
659 B
JavaScript

import base58 from 'bs58'
import nacl from 'tweetnacl'
/**
* @public
* Ed25519 keypair in base58 (as BigchainDB expects base58 keys)
* @type {Object}
* @param {Buffer} [seed] A seed that will be used as a key derivation function
* @property {string} publicKey
* @property {string} privateKey
*/
export default function Ed25519Keypair(seed) {
const keyPair = seed ? nacl.sign.keyPair.fromSeed(seed) : nacl.sign.keyPair()
this.publicKey = base58.encode(keyPair.publicKey)
// tweetnacl's generated secret key is the secret key + public key (resulting in a 64-byte buffer)
this.privateKey = base58.encode(keyPair.secretKey.slice(0, 32))
}