function forEachEnvelopeItem(
  envelope,
  callback,
) {
  const envelopeItems = envelope[1];

  for (const envelopeItem of envelopeItems) {
    const envelopeItemType = envelopeItem[0].type;
    const result = callback(envelopeItem, envelopeItemType);

    if (result) {
      return true;
    }
  }

  return false;
}
Convenience function to loop through the items and item types of an envelope.
(This function was mostly created because working with envelope types is painful at the moment)

If the callback returns true, the rest of the items will be skipped.