async createEncryptTransformer({recipients, keyResolver, chunkSize}) {
    if(!(Array.isArray(recipients) && recipients.length > 0)) {
      throw new TypeError('"recipients" must be a non-empty array.');
    }
    // ensure all recipients use the supported key agreement algorithm
    const {keyAgreement} = this;
    const {JWE_ALG: alg} = keyAgreement;
    if(!recipients.every(e => e.header && e.header.alg === alg)) {
      throw new Error(`All recipients must use the algorithm "${alg}".`);
    }
    const {cipher} = this;

    // generate a CEK for encrypting the content
    const cek = await cipher.generateKey();

    // derive ephemeral ECDH key pair to use with all recipients
    const ephemeralKeyPair = await keyAgreement.deriveEphemeralKeyPair();

    recipients = await Promise.all(recipients.map(
      recipient => this._createRecipient(
        {recipient, cek, ephemeralKeyPair, keyResolver})));

    // create shared protected header as associated authenticated data (aad)
    // ASCII(BASE64URL(UTF8(JWE Protected Header)))
    const enc = cipher.JWE_ENC;
    const jweProtectedHeader = JSON.stringify({enc});
    const encodedProtectedHeader =
      base64url.encode(stringToUint8Array(jweProtectedHeader));
    // UTF8-encoding a base64url-encoded string is the same as ASCII
    const additionalData = stringToUint8Array(encodedProtectedHeader);

    return new EncryptTransformer({
      recipients,
      encodedProtectedHeader,
      cipher,
      additionalData,
      cek,
      chunkSize
    });
  }
/**
   * Creates an EncryptTransformer that can be used to encrypt one or more
   * chunks of data.
   *
   * A list of recipients must be given in the `recipients` array, identified
   * by key agreement keys. An ephemeral ECDH key will be generated and used to
   * derive shared KEKs that will wrap a randomly generated CEK. Each recipient
   * in the `recipients` array will be updated to include the generated
   * ephemeral ECDH key.
   *
   * @param {object} options - Options for the transformer.
   * @param {Array} options.recipients - An array of recipients for the
   *   encrypted content.
   * @param {Function} options.keyResolver - A function that returns
   *   a Promise that resolves a key ID to a DH public key.
   * @param {number} [options.chunkSize=1048576] - The size, in bytes, of the
   *   chunks to break the incoming data into (only applies if returning a
   *   stream).
   *
   * @returns {Promise<EncryptTransformer>} - Resolves to an EncryptTransformer.
   */
Creates an EncryptTransformer that can be used to encrypt one or more
chunks of data.

A list of recipients must be given in the `recipients` array, identified
by key agreement keys. An ephemeral ECDH key will be generated and used to
derive shared KEKs that will wrap a randomly generated CEK. Each recipient
in the `recipients` array will be updated to include the generated
ephemeral ECDH key.

@param {object} options - Options for the transformer.
@param {Array} options.recipients - An array of recipients for the
encrypted content.
@param {Function} options.keyResolver - A function that returns
a Promise that resolves a key ID to a DH public key.
@param {number} [options.chunkSize=1048576] - The size, in bytes, of the
chunks to break the incoming data into (only applies if returning a
stream).

@returns {Promise} - Resolves to an EncryptTransformer.
Creates an EncryptTransformer that can be used to encrypt one or more chunks of data . A list of recipients must be given in the ` recipients ` array identified by key agreement keys . An ephemeral ECDH key will be generated and used to derive shared KEKs that will wrap a randomly generated CEK . Each recipient in the ` recipients ` array will be updated to include the generated ephemeral ECDH key . @param { object } options - Options for the transformer . @param { Array } options . recipients - An array of recipients for the encrypted content . @param { Function } options . keyResolver - A function that returns a Promise that resolves a key ID to a DH public key . @param { number } [ options . chunkSize = 1048576 ] - The size in bytes of the chunks to break the incoming data into ( only applies if returning a stream ) . @returns { Promise } - Resolves to an EncryptTransformer .
async createEncryptTransformer({recipients, keyResolver, chunkSize}) {
    if(!(Array.isArray(recipients) && recipients.length > 0)) {
      throw new TypeError('"recipients" must be a non-empty array.');
    }
    const {keyAgreement} = this;
    const {JWE_ALG: alg} = keyAgreement;
    if(!recipients.every(e => e.header && e.header.alg === alg)) {
      throw new Error(`All recipients must use the algorithm "${alg}".`);
    }
    const {cipher} = this;
    const cek = await cipher.generateKey();
    const ephemeralKeyPair = await keyAgreement.deriveEphemeralKeyPair();
    recipients = await Promise.all(recipients.map(
      recipient => this._createRecipient(
        {recipient, cek, ephemeralKeyPair, keyResolver})));
    const enc = cipher.JWE_ENC;
    const jweProtectedHeader = JSON.stringify({enc});
    const encodedProtectedHeader =
      base64url.encode(stringToUint8Array(jweProtectedHeader));
    const additionalData = stringToUint8Array(encodedProtectedHeader);
    return new EncryptTransformer({
      recipients,
      encodedProtectedHeader,
      cipher,
      additionalData,
      cek,
      chunkSize
    });
  }
async createEncryptTransformer ( { recipients , keyResolver , chunkSize } ) { if ( ! ( Array . isArray ( recipients ) && recipients . length > 0 ) ) { throw new TypeError ( '"recipients" must be a non-empty array.' ) ; } const { keyAgreement } = this ; const { JWE_ALG : alg } = keyAgreement ; if ( ! recipients . every ( e => e . header && e . header . alg === alg ) ) { throw new Error ( ` ${ alg } ` ) ; } const { cipher } = this ; const cek = await cipher . generateKey ( ) ; const ephemeralKeyPair = await keyAgreement . deriveEphemeralKeyPair ( ) ; recipients = await Promise . all ( recipients . map ( recipient => this . _createRecipient ( { recipient , cek , ephemeralKeyPair , keyResolver } ) ) ) ; const enc = cipher . JWE_ENC ; const jweProtectedHeader = JSON . stringify ( { enc } ) ; const encodedProtectedHeader = base64url . encode ( stringToUint8Array ( jweProtectedHeader ) ) ; const additionalData = stringToUint8Array ( encodedProtectedHeader ) ; return new EncryptTransformer ( { recipients , encodedProtectedHeader , cipher , additionalData , cek , chunkSize } ) ; }
Creates an EncryptTransformer that can be used to encrypt one or more
 chunks of data.
Creates an EncryptTransformer that can be used to encrypt one or more chunks of data .
// ensure all recipients use the supported key agreement algorithm // generate a CEK for encrypting the content // derive ephemeral ECDH key pair to use with all recipients // create shared protected header as associated authenticated data (aad) // ASCII(BASE64URL(UTF8(JWE Protected Header))) // UTF8-encoding a base64url-encoded string is the same as ASCII