index.js
function unbox(box, ifFrom, fallback) { // eslint-disable-line no-shadow
    if (ifFrom == null) { // eslint-disable-line
      ifFrom = () => true;
    }
    if (typeof ifFrom !== 'function') {
      throw new TypeError(`Expected function not ${ ifFrom }`);
    }
    const boxData = boxes.get(box);
    if (!boxData) {
      return fallback;
    }
    const { boxerPriv, boxerPub, value, mayOpen } = boxData;
    // Require mutual consent
    // TODO: Is this the object identity equivalent of an
    // out-of-order verify/decrypt fault?
    // http://world.std.com/~dtd/sign_encrypt/sign_encrypt7.html
    return (privateKey(() => mayOpen(publicKey)) === true &&
            boxerPriv(() => ifFrom(boxerPub)) === true) ?
      value :
      fallback;
  }
function unbox(box, ifFrom, fallback) { // eslint-disable-line no-shadow
    if (ifFrom == null) { // eslint-disable-line
      ifFrom = () => true;
    }
    if (typeof ifFrom !== 'function') {
      throw new TypeError(`Expected function not ${ ifFrom }`);
    }
    const boxData = boxes.get(box);
    if (!boxData) {
      return fallback;
    }
    const { boxerPriv, boxerPub, value, mayOpen } = boxData;
    // Require mutual consent
    // TODO: Is this the object identity equivalent of an
    // out-of-order verify/decrypt fault?
    // http://world.std.com/~dtd/sign_encrypt/sign_encrypt7.html
    return (privateKey(() => mayOpen(publicKey)) === true &&
            boxerPriv(() => ifFrom(boxerPub)) === true) ?
      value :
      fallback;
  }
function unbox ( box , ifFrom , fallback ) { // eslint-disable-line no-shadow if ( ifFrom == null ) { // eslint-disable-line ifFrom = ( ) => true ; } if ( typeof ifFrom !== 'function' ) { throw new TypeError ( ` ${ ifFrom } ` ) ; } const boxData = boxes . get ( box ) ; if ( ! boxData ) { return fallback ; } const { boxerPriv , boxerPub , value , mayOpen } = boxData ; // Require mutual consent // TODO: Is this the object identity equivalent of an // out-of-order verify/decrypt fault? // http://world.std.com/~dtd/sign_encrypt/sign_encrypt7.html return ( privateKey ( ( ) => mayOpen ( publicKey ) ) === true && boxerPriv ( ( ) => ifFrom ( boxerPub ) ) === true ) ? value : fallback ; }
Tries to open a box.

@param {*} box the box to unbox.
@param {?function(function():boolean):boolean} ifFrom
if the box may be opened by this unboxer's owner,
then ifFrom receives the publicKey of the box creator.
It should return true to allow unboxing to proceed.
@param {*} fallback a value to substitute if unboxing failed.
Defaults to undefined.
@return {*} the value if unboxing is allowed or fallback otherwise.
Tries to open a box .