
  // Support methods for the JNI class

  public final static byte[] aes(byte[] jarg1, byte[] jarg2, long jarg3) {
      return aes(jarg1, jarg2, jarg3, null);
  }

  public final static String base58check_from_bytes(byte[] bytes) {
      return base58_from_bytes(bytes, BASE58_FLAG_CHECKSUM);
  }

  private final static byte[] base58_to_bytes(String base58, long flags) {
      final byte buf[] = new byte[base58_get_length(base58)];
      final int len = base58_to_bytes(base58, flags, buf);
      return trimBuffer(buf, len);
  }

  public final static byte[] base58_to_bytes(String base58) {
      return base58_to_bytes(base58, 0);
  }

  public final static byte[] base58check_to_bytes(String base58) {
      return base58_to_bytes(base58, BASE58_FLAG_CHECKSUM);
  }

  public final static Object bip32_pub_key_init(final int version, final int depth, final int childNum,
                                         final byte[] chainCode, final byte[] pubKey) {
      return Wally.bip32_key_init(version, depth, childNum, chainCode, pubKey, null, null, null);
  }

  public final static Object bip32_priv_key_init(final int version, final int depth, final int childNum,
                                                 final byte[] chainCode, final byte[] privateKey) {
      return Wally.bip32_key_init(version, depth, childNum, chainCode, null, privateKey, null, null);
  }

  public final static byte[] bip32_key_get_chain_code(Object jarg1) {
      return bip32_key_get_chain_code(jarg1, null);
  }

  public final static byte[] bip32_key_get_parent160(Object jarg1) {
      return bip32_key_get_parent160(jarg1, null);
  }

  public final static byte[] bip32_key_get_priv_key(Object jarg1) {
      return bip32_key_get_priv_key(jarg1, null);
  }

  public final static byte[] bip32_key_get_hash160(Object jarg1) {
      return bip32_key_get_hash160(jarg1, null);
  }

  public final static byte[] bip32_key_get_pub_key(Object jarg1) {
      return bip32_key_get_pub_key(jarg1, null);
  }

  public final static byte[] bip32_key_serialize(Object jarg1, long jarg2) {
      return bip32_key_serialize(jarg1, jarg2, null);
  }

  public final static byte[] bip38_raw_from_private_key(byte[] jarg1, byte[] jarg2, long jarg3) {
      return bip38_raw_from_private_key(jarg1, jarg2, jarg3, null);
  }

  public final static byte[] bip38_to_private_key(String jarg1, byte[] jarg2, long jarg3) {
      return bip38_to_private_key(jarg1, jarg2, jarg3, null);
  }

  public final static byte[] sha256(byte[] jarg1) {
      return sha256(jarg1, null);
  }

  public final static byte[] sha256d(byte[] jarg1) {
      return sha256d(jarg1, null);
  }

  public final static byte[] sha512(byte[] jarg1) {
      return sha512(jarg1, null);
  }

  public final static byte[] hash160(byte[] jarg1) {
      return hash160(jarg1, null);
  }

  public final static byte[] hex_to_bytes(String jarg1) {
      final byte[] ret = new byte[jarg1.length() / 2];
      if (hex_to_bytes(jarg1, ret) != ret.length)
          throw new IllegalArgumentException("invalid hex string length");
      return ret;
  }

  public final static byte[] hmac_sha256(byte[] jarg1, byte[] jarg2) {
      return hmac_sha256(jarg1, jarg2, null);
  }

  public final static byte[] hmac_sha512(byte[] jarg1, byte[] jarg2) {
      return hmac_sha512(jarg1, jarg2, null);
  }

  public final static byte[] pbkdf2_hmac_sha256(byte[] jarg1, byte[] jarg2, long jarg3, long jarg4) {
      return pbkdf2_hmac_sha256(jarg1, jarg2, jarg3, jarg4, null);
  }

  public final static byte[] pbkdf2_hmac_sha512(byte[] jarg1, byte[] jarg2, long jarg3, long jarg4) {
      return pbkdf2_hmac_sha512(jarg1, jarg2, jarg3, jarg4, null);
  }

  public final static byte[] ec_public_key_from_private_key(byte[] jarg1) {
      return ec_public_key_from_private_key(jarg1, null);
  }

  public final static byte[] ec_sig_from_bytes(byte[] jarg1, byte[] jarg2, long jarg3) {
      return ec_sig_from_bytes(jarg1, jarg2, jarg3, null);
  }

  public final static byte[] ec_sig_normalize(byte[] jarg1) {
      return ec_sig_normalize(jarg1, null);
  }

  public final static byte[] ec_sig_from_der(byte[] jarg1) {
      return ec_sig_from_der(jarg1, null);
  }

  public final static byte[] format_bitcoin_message(byte[] jarg1, long jarg2) {
      int msg_len = SHA256_LEN;
      if ((jarg2 & BITCOIN_MESSAGE_FLAG_HASH) == 0)
          msg_len = 25 + jarg1.length + (jarg1.length < 253 ? 1 : 3);
      final byte[] ret = new byte[msg_len];
      if (format_bitcoin_message(jarg1, jarg2, ret) != ret.length)
          throw new IllegalArgumentException("Invalid formatted message");
      return ret;
  }

  private final static byte[] _get_push_buf(final int in_buf_len, final int extra_bytes) {
      int len = 5;
      if (in_buf_len < 76)
          len = 1;
      else if (in_buf_len < 256)
          len = 2;
      else if (in_buf_len < 65536)
          len = 3;

      return new byte[len + in_buf_len + extra_bytes];
  }

  public final static byte[] script_push_from_bytes(byte[] jarg1, long flags) {
      final byte[] ret = _get_push_buf(jarg1.length, 0);
      if (script_push_from_bytes(jarg1, flags, ret) != ret.length)
          throw new IllegalArgumentException("Error encoding push");
      return ret;
  }

  public final static byte[] witness_program_from_bytes(byte[] jarg1, long flags) {
      int len = jarg1.length;
      if ((flags & WALLY_SCRIPT_HASH160) != 0)
        len = HASH160_LEN;
      else if ((flags & WALLY_SCRIPT_SHA256) != 0)
        len = SHA256_LEN;
      final byte[] ret = _get_push_buf(len, 1);
      if (witness_program_from_bytes(jarg1, flags, ret) != ret.length)
          throw new IllegalArgumentException("Error encoding witness program");
      return ret;
  }

  public static final byte[] addr_segwit_to_bytes(String jarg1, String jarg2, long jarg3) {
      final byte[] buf = new byte[32 + 2]; /* Largest v0 witness script possible */
      final int len = addr_segwit_to_bytes(jarg1, jarg2, jarg3, buf);
      return trimBuffer(buf, len);
  }

  public final static byte[] asset_generator_from_bytes(byte[] jarg1, byte[] jarg2) {
      return asset_generator_from_bytes(jarg1, jarg2, null);
  }

  public final static byte[] asset_final_vbf(long[] jarg1, long jarg2, byte[] jarg3, byte[] jarg4) {
      return asset_final_vbf(jarg1, jarg2, jarg3, jarg4, null);
  }

  public final static byte[] asset_value_commitment(long jarg1, byte[] jarg2, byte[] jarg3) {
      return asset_value_commitment(jarg1, jarg2, jarg3, null);
  }

  private final static byte[] trimBuffer(final byte[] buf, final int len) {
      if (len > buf.length) throw new IllegalArgumentException();
      return len == buf.length ? buf: java.util.Arrays.copyOf(buf, len);
  }

  public final static byte[] asset_rangeproof(long jarg1, byte[] jarg2, byte[] jarg3, byte[] jarg4,
                                              byte[] jarg5, byte[] jarg6, byte[] jarg7, byte[] jarg8,
                                              byte[] jarg9, int jarg10) {
      final byte[] buf = new byte[ASSET_RANGEPROOF_MAX_LEN];
      final int len = asset_rangeproof(jarg1, jarg2, jarg3, jarg4, jarg5, jarg6, jarg7, jarg8,
                                       jarg9, jarg10, buf);
      return trimBuffer(buf, len);
  }

  public final static byte[] asset_surjectionproof(byte[] jarg1, byte[] jarg2, byte[] jarg3,
                                                   byte[] jarg4, byte[] jarg5, byte[] jarg6, byte[] jarg7) {
      final byte[] buf = new byte[asset_surjectionproof_size(jarg5.length / ASSET_TAG_LEN)];
      final int len = asset_surjectionproof(jarg1, jarg2, jarg3, jarg4, jarg5, jarg6, jarg7, buf);
      return trimBuffer(buf, len);
  }

  public final static long asset_unblind(byte[] pub_key, byte[] priv_key, byte[] proof,
                                         byte[] commitment, byte[] extra_in,
                                         byte[] generator,
                                         final java.util.List<byte[]> outputs) {
      // We return asset_out, abf_out, vbf_out in the passed list
      for (int i = 0; i < 3; i++) // asset_out, abf_out, vbf_out
          outputs.add(new byte[ASSET_TAG_LEN]);
      return asset_unblind(pub_key, priv_key, proof, commitment, extra_in, generator,
                           outputs.get(0), outputs.get(1), outputs.get(2));
  }
}
