lib/identity.js
function Identity(userID, passphrase, keyPair) {
  if (!(this instanceof Identity)) {
    return new Identity(userID, passphrase, keyPair);
  }

  assert(typeof userID === 'string', 'Invalid userID supplied');
  assert(typeof passphrase === 'string', 'Invalid passphrase supplied');

  this._publicKeyArmored = keyPair.publicKey.toString();
  this._privateKeyArmored = keyPair.privateKey.toString();

  this.userID = userID;
  this.publicKey = pgp.key.readArmored(this._publicKeyArmored).keys[0];
  this.privateKey = pgp.key.readArmored(this._privateKeyArmored).keys[0];

  assert(this.privateKey.decrypt(passphrase), 'Failed to decrypt private key');
}
function Identity(userID, passphrase, keyPair) {
  if (!(this instanceof Identity)) {
    return new Identity(userID, passphrase, keyPair);
  }

  assert(typeof userID === 'string', 'Invalid userID supplied');
  assert(typeof passphrase === 'string', 'Invalid passphrase supplied');

  this._publicKeyArmored = keyPair.publicKey.toString();
  this._privateKeyArmored = keyPair.privateKey.toString();

  this.userID = userID;
  this.publicKey = pgp.key.readArmored(this._publicKeyArmored).keys[0];
  this.privateKey = pgp.key.readArmored(this._privateKeyArmored).keys[0];

  assert(this.privateKey.decrypt(passphrase), 'Failed to decrypt private key');
}
function Identity ( userID , passphrase , keyPair ) { if ( ! ( this instanceof Identity ) ) { return new Identity ( userID , passphrase , keyPair ) ; } assert ( typeof userID === 'string' , 'Invalid userID supplied' ) ; assert ( typeof passphrase === 'string' , 'Invalid passphrase supplied' ) ; this . _publicKeyArmored = keyPair . publicKey . toString ( ) ; this . _privateKeyArmored = keyPair . privateKey . toString ( ) ; this . userID = userID ; this . publicKey = pgp . key . readArmored ( this . _publicKeyArmored ) . keys [ 0 ] ; this . privateKey = pgp . key . readArmored ( this . _privateKeyArmored ) . keys [ 0 ] ; assert ( this . privateKey . decrypt ( passphrase ) , 'Failed to decrypt private key' ) ; }
An identity is represented by a PGP key pair and user ID
@constructor
@param {string} userID
@param {string} passphrase
@param {object} keyPair
@param {string} keyPair.publicKey
@param {string} keyPair.privateKey
An identity is represented by a PGP key pair and user ID