<commit_before>import padEnd from 'lodash/padEnd';
import xdr from '../generated/stellar-xdr_generated';
import { Keypair } from '../keypair';
import { StrKey } from '../strkey';

/**
 * Returns an XDR AllowTrustOp. An "allow trust" operation authorizes another
 * account to hold your account's credit for a given asset.
 * @function
 * @alias Operation.allowTrust
 * @param {object} opts Options object
 * @param {string} opts.trustor - The trusting account (the one being authorized)
 * @param {string} opts.assetCode - The asset code being authorized.
 * @param {boolean|number} opts.authorize - True to authorize the line, false to deauthorize.
 * @param {string} [opts.source] - The source account (defaults to transaction source).
 * @returns {xdr.AllowTrustOp} Allow Trust operation
 */
export function allowTrust(opts) {
  if (!StrKey.isValidEd25519PublicKey(opts.trustor)) {
    throw new Error('trustor is invalid');
  }
  const attributes = {};
  attributes.trustor = Keypair.fromPublicKey(opts.trustor).xdrAccountId();
  if (opts.assetCode.length <= 4) {
    const code = padEnd(opts.assetCode, 4, '\0');
    attributes.asset = xdr.AllowTrustOpAsset.assetTypeCreditAlphanum4(code);
  } else if (opts.assetCode.length <= 12) {
    const code = padEnd(opts.assetCode, 12, '\0');
    attributes.asset = xdr.AllowTrustOpAsset.assetTypeCreditAlphanum12(code);
  } else {
    throw new Error('Asset code must be 12 characters at max.');
  }

  if (typeof opts.authorize === 'boolean') {
    attributes.authorize = +opts.authorize;
  } else {
    attributes.authorize = opts.authorize;
  }

  const allowTrustOp = new xdr.AllowTrustOp(attributes);<commit_msg>Use authorizedFlag().value instead of casting to 1.<commit_after>import padEnd from 'lodash/padEnd';
import xdr from '../generated/stellar-xdr_generated';
import { Keypair } from '../keypair';
import { StrKey } from '../strkey';

/**
 * Returns an XDR AllowTrustOp. An "allow trust" operation authorizes another
 * account to hold your account's credit for a given asset.
 * @function
 * @alias Operation.allowTrust
 * @param {object} opts Options object
 * @param {string} opts.trustor - The trusting account (the one being authorized)
 * @param {string} opts.assetCode - The asset code being authorized.
 * @param {boolean|number} opts.authorize - True to authorize the line, false to deauthorize.
 * @param {string} [opts.source] - The source account (defaults to transaction source).
 * @returns {xdr.AllowTrustOp} Allow Trust operation
 */
export function allowTrust(opts) {
  if (!StrKey.isValidEd25519PublicKey(opts.trustor)) {
    throw new Error('trustor is invalid');
  }
  const attributes = {};
  attributes.trustor = Keypair.fromPublicKey(opts.trustor).xdrAccountId();
  if (opts.assetCode.length <= 4) {
    const code = padEnd(opts.assetCode, 4, '\0');
    attributes.asset = xdr.AllowTrustOpAsset.assetTypeCreditAlphanum4(code);
  } else if (opts.assetCode.length <= 12) {
    const code = padEnd(opts.assetCode, 12, '\0');
    attributes.asset = xdr.AllowTrustOpAsset.assetTypeCreditAlphanum12(code);
  } else {
    throw new Error('Asset code must be 12 characters at max.');
  }

  if (typeof opts.authorize === 'boolean') {
    if (opts.authorize) {
      attributes.authorize = xdr.TrustLineFlags.authorizedFlag().value;
    } else {
      attributes.authorize = 0;
    }
  } else {
    attributes.authorize = opts.authorize;
  }

  const allowTrustOp = new xdr.AllowTrustOp(attributes);
{'fraction_non_alphanumeric': 0.12410020155485171, 'fraction_numerical': 0.010941549093003168, 'mean_word_length': 4.116347569955817, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5912104', 'n_tokens_mistral': 1104, 'n_tokens_neox': 1030, 'n_words': 304}