mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2024-11-22 01:36:56 +01:00
seed from hash of secret
This commit is contained in:
parent
a338a5c570
commit
f5123832bf
8
dist/node/index.js
vendored
8
dist/node/index.js
vendored
@ -3,11 +3,11 @@
|
|||||||
Object.defineProperty(exports, "__esModule", {
|
Object.defineProperty(exports, "__esModule", {
|
||||||
value: true
|
value: true
|
||||||
});
|
});
|
||||||
exports.Connection = exports.Transaction = exports.Ed25519KeyPair = undefined;
|
exports.Connection = exports.Transaction = exports.Ed25519Keypair = undefined;
|
||||||
|
|
||||||
var _Ed25519Keypair = require('./Ed25519Keypair');
|
var _Ed25519Keypair2 = require('./Ed25519Keypair');
|
||||||
|
|
||||||
var _Ed25519Keypair2 = _interopRequireDefault(_Ed25519Keypair);
|
var _Ed25519Keypair3 = _interopRequireDefault(_Ed25519Keypair2);
|
||||||
|
|
||||||
var _transaction = require('./transaction');
|
var _transaction = require('./transaction');
|
||||||
|
|
||||||
@ -21,6 +21,6 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|||||||
|
|
||||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||||
|
|
||||||
exports.Ed25519KeyPair = _Ed25519Keypair2.default;
|
exports.Ed25519Keypair = _Ed25519Keypair3.default;
|
||||||
exports.Transaction = _Transaction;
|
exports.Transaction = _Transaction;
|
||||||
exports.Connection = _Connection;
|
exports.Connection = _Connection;
|
@ -1,14 +1,26 @@
|
|||||||
import base58 from 'bs58';
|
import base58 from 'bs58';
|
||||||
import nacl from 'tweetnacl';
|
import nacl from 'tweetnacl';
|
||||||
|
import sha3 from 'js-sha3';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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
|
||||||
* @property {string} publicKey
|
* @property {string} publicKey
|
||||||
* @property {string} privateKey
|
* @property {string} privateKey
|
||||||
*/
|
*/
|
||||||
export default function Ed25519Keypair() {
|
export default function Ed25519Keypair(secret) {
|
||||||
const keyPair = nacl.sign.keyPair();
|
let 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));
|
||||||
|
Loading…
Reference in New Issue
Block a user