1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-11-22 17:50:09 +01:00

Merge pull request #8 from bigchaindb/create-key-from-seed

Create key from seed
This commit is contained in:
Matthias Kretschmann 2017-06-12 14:05:09 +02:00 committed by GitHub
commit 361c21ba1c
2 changed files with 4 additions and 14 deletions

View File

@ -6,22 +6,12 @@ import sha3 from 'js-sha3';
* @public * @public
* @class Keypair Ed25519 keypair in base58 (as BigchainDB expects base58 keys) * @class Keypair Ed25519 keypair in base58 (as BigchainDB expects base58 keys)
* @type {Object} * @type {Object}
* @param {number} [secret] A seed that will be used as a key derivation function * @param {Buffer} [seed] A seed that will be used as a key derivation function
* @property {string} publicKey * @property {string} publicKey
* @property {string} privateKey * @property {string} privateKey
*/ */
export default function Ed25519Keypair(secret) { export default function Ed25519Keypair(seed) {
let keyPair; const keyPair = seed ? nacl.sign.keyPair.fromSeed(seed) : nacl.sign.keyPair();
if (secret) {
// Quick and dirty: use key derivation function instead
const secretHash = sha3.sha3_256
.create()
.update(secret)
.array();
keyPair = nacl.sign.keyPair.fromSeed(new Uint8Array(secretHash))
} else {
keyPair = nacl.sign.keyPair();
}
this.publicKey = base58.encode(keyPair.publicKey); this.publicKey = base58.encode(keyPair.publicKey);
// tweetnacl's generated secret key is the secret key + public key (resulting in a 64-byte buffer) // 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)); this.privateKey = base58.encode(keyPair.secretKey.slice(0, 32));

View File

@ -8,7 +8,7 @@
*/ */
export default function makeOutput(condition, amount = 1) { export default function makeOutput(condition, amount = 1) {
return { return {
amount: amount, amount: amount.toString(),
condition, condition,
'public_keys': condition.details.hasOwnProperty('public_key') ? 'public_keys': condition.details.hasOwnProperty('public_key') ?
[condition.details.public_key] : [], [condition.details.public_key] : [],