{"size": 1412, "ext": "js", "max_stars_repo_path": "packages/common/src/Coding/Pascal/Keys/PrivateKey.js", "max_stars_repo_name": "pascal-triangle/sbx", "max_stars_repo_stars_event_min_datetime": "2019-04-08T09:14:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-14T00:27:13.000Z", "max_issues_repo_path": "packages/common/src/Coding/Pascal/Keys/PrivateKey.js", "max_issues_repo_name": "pascal-triangle/sbx", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/common/src/Coding/Pascal/Keys/PrivateKey.js", "max_forks_repo_name": "pascal-triangle/sbx", "max_forks_repo_forks_event_min_datetime": "2019-05-31T10:18:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-02T19:03:50.000Z"}
{"max_stars_count": 7, "max_issues_count": null, "max_forks_count": 4, "avg_line_length": 23.9322033898, "max_line_length": 74, "alphanum_fraction": 0.6437677054}
/**
 * Copyright (c) Benjamin Ansbach - all rights reserved.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

const Curve = require('./Curve');
const BytesWithLength = require('../../Core/BytesWithLength');
const CompositeType = require('../../CompositeType');
const PrivateKeyType = require('./../../../../src/Types/Keys/PrivateKey');

/**
 * A coder for a private key.
 */
class PrivateKey extends CompositeType {
  /**
   * Constructor.
   *
   * @param {String} id
   */
  constructor(id = null) {
    super(id || 'private_key');
    this.addSubType(
      new Curve('curve')
    );
    this.addSubType(
      new BytesWithLength('key', 2)
        .description('The private key value.')
    );
  }

  /**
   * Reads a value and returns a new PascalCoin PublicKey instance.
   *
   * @param {BC|Buffer|Uint8Array|String} bc
   * @param {Object} options
   * @param {*} all
   * @returns {PrivateKeyType}
   */
  decodeFromBytes(bc, options = {}, all = null) {
    const decoded = super.decodeFromBytes(bc);

    return new PrivateKeyType(decoded.key, decoded.curve);
  }

  /**
   * Reads a value and returns a new PascalCoin PublicKey instance.
   *
   * @param {PrivateKeyType} value
   * @returns {PrivateKeyType}
   */
  encodeToBytes(value) {
    return super.encodeToBytes(value);
  }
}

module.exports = PrivateKey;
