lib/crypto.js
function deriveKeypair(parent_secret, child_name, signature_scheme) {
  if (!signature_scheme) {
    signature_scheme = 'ec_secp256k1';
  }

  var pair = {};

  if (signature_scheme === 'ec_secp256k1') {

    pair.private = deriveSecret(parent_secret, child_name, 'sha256');

    // If the private key is greater than the curve modulus we
    // use a counter to get a new random secret
    var modulus = new BigInteger(ecurve.getCurveByName('secp256k1').n, 16);
    var counter = 1;
    while (!pair.private || modulus.compareTo(pair.private) < 0) {
      pair.private = deriveSecret(parent_secret, child_name + '_' + counter, 'sha256');
      counter += 1;
    }

    pair.public = new bitcoinjs.ECKey(new BigInteger(pair.private, 16), false).pub.toHex();

  } else {

    throw new Error('Signature scheme: ' + signature_scheme + ' not currently supported');

  }

  return pair;
}
function deriveKeypair(parent_secret, child_name, signature_scheme) {
  if (!signature_scheme) {
    signature_scheme = 'ec_secp256k1';
  }

  var pair = {};

  if (signature_scheme === 'ec_secp256k1') {

    pair.private = deriveSecret(parent_secret, child_name, 'sha256');

    // If the private key is greater than the curve modulus we
    // use a counter to get a new random secret
    var modulus = new BigInteger(ecurve.getCurveByName('secp256k1').n, 16);
    var counter = 1;
    while (!pair.private || modulus.compareTo(pair.private) < 0) {
      pair.private = deriveSecret(parent_secret, child_name + '_' + counter, 'sha256');
      counter += 1;
    }

    pair.public = new bitcoinjs.ECKey(new BigInteger(pair.private, 16), false).pub.toHex();

  } else {

    throw new Error('Signature scheme: ' + signature_scheme + ' not currently supported');

  }

  return pair;
}
function deriveKeypair ( parent_secret , child_name , signature_scheme ) { if ( ! signature_scheme ) { signature_scheme = 'ec_secp256k1' ; } var pair = { } ; if ( signature_scheme === 'ec_secp256k1' ) { pair . private = deriveSecret ( parent_secret , child_name , 'sha256' ) ; // If the private key is greater than the curve modulus we // use a counter to get a new random secret var modulus = new BigInteger ( ecurve . getCurveByName ( 'secp256k1' ) . n , 16 ) ; var counter = 1 ; while ( ! pair . private || modulus . compareTo ( pair . private ) < 0 ) { pair . private = deriveSecret ( parent_secret , child_name + '_' + counter , 'sha256' ) ; counter += 1 ; } pair . public = new bitcoinjs . ECKey ( new BigInteger ( pair . private , 16 ) , false ) . pub . toHex ( ) ; } else { throw new Error ( 'Signature scheme: ' + signature_scheme + ' not currently supported' ) ; } return pair ; }
Derive a public and private key from a "parent" secret.

@param {String} parent_secret
@param {String} child_name
@param {String} ['secp256k1'] signature_scheme

@returns {Object} Object with "public" and "private" fields
Derive a public and private key from a parent secret .