lib/index.js
function find3rdPartyCaveatParts(macaroonWithCaveat, secretPem) {
  var macaroonSerialized = macaroonWithCaveat.macaroon;
  var discharge = macaroonWithCaveat.discharge;

  var key = new NodeRSA();
  key.importKey(secretPem);

  var macaroon = MacaroonsBuilder.deserialize(macaroonSerialized);

  var getDischargeParts = getMacPartsFn(" = ");

  var macObj = macaroonPairsToObj(key.decrypt(discharge).toString('utf8'), getDischargeParts);

  var caveatKey = macObj.caveat_key;
  var message = macObj.message;

  var macaroon = MacaroonsBuilder.deserialize(macaroonSerialized);

  var getMacaroonParts = getMacPartsFn(" ");
  var stringMacPairs = macStringToPairs(macaroon.inspect(), getMacaroonParts);

  var identifierLoc = _.findIndex(stringMacPairs, function (pair) {
    return pair[0] === "cid" && pair[1] === "enc = " + discharge;
  });

  var caveatIdentifier = stringMacPairs[identifierLoc][1];
  var caveatLocation = stringMacPairs[identifierLoc + 2][1];//kind of a hack

  return {
    caveatKey: caveatKey,
    macRaw: macaroonSerialized,
    thirdParty: {
      messageObj: macaroonPairsToObj(macObj.message, getDischargeParts),
      identifier: caveatIdentifier,
      location: caveatLocation
    }
  };
}
function find3rdPartyCaveatParts(macaroonWithCaveat, secretPem) {
  var macaroonSerialized = macaroonWithCaveat.macaroon;
  var discharge = macaroonWithCaveat.discharge;

  var key = new NodeRSA();
  key.importKey(secretPem);

  var macaroon = MacaroonsBuilder.deserialize(macaroonSerialized);

  var getDischargeParts = getMacPartsFn(" = ");

  var macObj = macaroonPairsToObj(key.decrypt(discharge).toString('utf8'), getDischargeParts);

  var caveatKey = macObj.caveat_key;
  var message = macObj.message;

  var macaroon = MacaroonsBuilder.deserialize(macaroonSerialized);

  var getMacaroonParts = getMacPartsFn(" ");
  var stringMacPairs = macStringToPairs(macaroon.inspect(), getMacaroonParts);

  var identifierLoc = _.findIndex(stringMacPairs, function (pair) {
    return pair[0] === "cid" && pair[1] === "enc = " + discharge;
  });

  var caveatIdentifier = stringMacPairs[identifierLoc][1];
  var caveatLocation = stringMacPairs[identifierLoc + 2][1];//kind of a hack

  return {
    caveatKey: caveatKey,
    macRaw: macaroonSerialized,
    thirdParty: {
      messageObj: macaroonPairsToObj(macObj.message, getDischargeParts),
      identifier: caveatIdentifier,
      location: caveatLocation
    }
  };
}
function find3rdPartyCaveatParts ( macaroonWithCaveat , secretPem ) { var macaroonSerialized = macaroonWithCaveat . macaroon ; var discharge = macaroonWithCaveat . discharge ; var key = new NodeRSA ( ) ; key . importKey ( secretPem ) ; var macaroon = MacaroonsBuilder . deserialize ( macaroonSerialized ) ; var getDischargeParts = getMacPartsFn ( " = " ) ; var macObj = macaroonPairsToObj ( key . decrypt ( discharge ) . toString ( 'utf8' ) , getDischargeParts ) ; var caveatKey = macObj . caveat_key ; var message = macObj . message ; var macaroon = MacaroonsBuilder . deserialize ( macaroonSerialized ) ; var getMacaroonParts = getMacPartsFn ( " " ) ; var stringMacPairs = macStringToPairs ( macaroon . inspect ( ) , getMacaroonParts ) ; var identifierLoc = _ . findIndex ( stringMacPairs , function ( pair ) { return pair [ 0 ] === "cid" && pair [ 1 ] === "enc = " + discharge ; } ) ; var caveatIdentifier = stringMacPairs [ identifierLoc ] [ 1 ] ; var caveatLocation = stringMacPairs [ identifierLoc + 2 ] [ 1 ] ; //kind of a hack return { caveatKey : caveatKey , macRaw : macaroonSerialized , thirdParty : { messageObj : macaroonPairsToObj ( macObj . message , getDischargeParts ) , identifier : caveatIdentifier , location : caveatLocation } } ; }
this needs to be separated into own library separate from 3rd party macaroons.
this needs to be separated into own library separate from 3rd party macaroons .