"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
Object.defineProperty(exports, "base64_variants", {
  enumerable: true,
  get: function () {
    return _libsodiumJsUtils.base64_variants;
  }
});
exports.crypto_aead_xchacha20poly1305_ietf_NPUBBYTES = exports.crypto_aead_xchacha20poly1305_ietf_KEYBYTES = void 0;
exports.crypto_aead_xchacha20poly1305_ietf_decrypt = crypto_aead_xchacha20poly1305_ietf_decrypt;
exports.crypto_aead_xchacha20poly1305_ietf_encrypt = crypto_aead_xchacha20poly1305_ietf_encrypt;
exports.crypto_aead_xchacha20poly1305_ietf_keygen = crypto_aead_xchacha20poly1305_ietf_keygen;
exports.crypto_box_SECRETKEYBYTES = exports.crypto_box_PUBLICKEYBYTES = exports.crypto_box_NONCEBYTES = void 0;
exports.crypto_box_easy = crypto_box_easy;
exports.crypto_box_keypair = crypto_box_keypair;
exports.crypto_box_open_easy = crypto_box_open_easy;
exports.crypto_kdf_KEYBYTES = exports.crypto_kdf_CONTEXTBYTES = void 0;
exports.crypto_kdf_derive_from_key = crypto_kdf_derive_from_key;
exports.crypto_kdf_keygen = crypto_kdf_keygen;
exports.crypto_pwhash = crypto_pwhash;
exports.crypto_secretbox_NONCEBYTES = exports.crypto_secretbox_KEYBYTES = exports.crypto_pwhash_SALTBYTES = exports.crypto_pwhash_OPSLIMIT_INTERACTIVE = exports.crypto_pwhash_MEMLIMIT_INTERACTIVE = exports.crypto_pwhash_BYTES_MIN = exports.crypto_pwhash_BYTES_MAX = exports.crypto_pwhash_ALG_DEFAULT = void 0;
exports.crypto_secretbox_easy = crypto_secretbox_easy;
exports.crypto_secretbox_keygen = crypto_secretbox_keygen;
exports.crypto_secretbox_open_easy = crypto_secretbox_open_easy;
exports.crypto_sign_detached = crypto_sign_detached;
exports.crypto_sign_keypair = crypto_sign_keypair;
exports.crypto_sign_verify_detached = crypto_sign_verify_detached;
exports.from_base64 = exports.default = void 0;
exports.randombytes_buf = randombytes_buf;
exports.randombytes_uniform = randombytes_uniform;
exports.to_base64 = exports.ready = void 0;
exports.to_hex = to_hex;
Object.defineProperty(exports, "to_string", {
  enumerable: true,
  get: function () {
    return _libsodiumJsUtils.to_string;
  }
});
var _libsodiumJsUtils = require("./libsodium-js-utils");
var _utils = require("./utils");
const crypto_secretbox_KEYBYTES = global.jsi_crypto_secretbox_KEYBYTES;
exports.crypto_secretbox_KEYBYTES = crypto_secretbox_KEYBYTES;
const crypto_secretbox_NONCEBYTES = global.jsi_crypto_secretbox_NONCEBYTES;
exports.crypto_secretbox_NONCEBYTES = crypto_secretbox_NONCEBYTES;
const crypto_pwhash_SALTBYTES = global.jsi_crypto_pwhash_SALTBYTES;
exports.crypto_pwhash_SALTBYTES = crypto_pwhash_SALTBYTES;
const crypto_pwhash_ALG_DEFAULT = global.jsi_crypto_pwhash_ALG_DEFAULT;
exports.crypto_pwhash_ALG_DEFAULT = crypto_pwhash_ALG_DEFAULT;
const crypto_pwhash_OPSLIMIT_INTERACTIVE = global.jsi_crypto_pwhash_OPSLIMIT_INTERACTIVE;
exports.crypto_pwhash_OPSLIMIT_INTERACTIVE = crypto_pwhash_OPSLIMIT_INTERACTIVE;
const crypto_pwhash_MEMLIMIT_INTERACTIVE = global.jsi_crypto_pwhash_MEMLIMIT_INTERACTIVE;
exports.crypto_pwhash_MEMLIMIT_INTERACTIVE = crypto_pwhash_MEMLIMIT_INTERACTIVE;
const crypto_box_PUBLICKEYBYTES = global.jsi_crypto_box_PUBLICKEYBYTES;
exports.crypto_box_PUBLICKEYBYTES = crypto_box_PUBLICKEYBYTES;
const crypto_box_SECRETKEYBYTES = global.jsi_crypto_box_SECRETKEYBYTES;
exports.crypto_box_SECRETKEYBYTES = crypto_box_SECRETKEYBYTES;
const crypto_box_NONCEBYTES = global.jsi_crypto_box_NONCEBYTES;
exports.crypto_box_NONCEBYTES = crypto_box_NONCEBYTES;
const crypto_aead_xchacha20poly1305_ietf_KEYBYTES = global.jsi_crypto_aead_xchacha20poly1305_ietf_KEYBYTES;
exports.crypto_aead_xchacha20poly1305_ietf_KEYBYTES = crypto_aead_xchacha20poly1305_ietf_KEYBYTES;
const crypto_aead_xchacha20poly1305_ietf_NPUBBYTES = global.jsi_crypto_aead_xchacha20poly1305_ietf_NPUBBYTES;
exports.crypto_aead_xchacha20poly1305_ietf_NPUBBYTES = crypto_aead_xchacha20poly1305_ietf_NPUBBYTES;
const crypto_kdf_KEYBYTES = global.jsi_crypto_kdf_KEYBYTES;
exports.crypto_kdf_KEYBYTES = crypto_kdf_KEYBYTES;
const crypto_pwhash_BYTES_MIN = global.jsi_crypto_pwhash_BYTES_MIN;
exports.crypto_pwhash_BYTES_MIN = crypto_pwhash_BYTES_MIN;
const crypto_pwhash_BYTES_MAX = global.jsi_crypto_pwhash_BYTES_MAX;
exports.crypto_pwhash_BYTES_MAX = crypto_pwhash_BYTES_MAX;
const crypto_kdf_CONTEXTBYTES = global.jsi_crypto_kdf_CONTEXTBYTES;
exports.crypto_kdf_CONTEXTBYTES = crypto_kdf_CONTEXTBYTES;
const from_base64 = (input, variant) => {
  const variantToUse = variant || _libsodiumJsUtils.base64_variants.URLSAFE_NO_PADDING;
  const result = global.jsi_from_base64_to_arraybuffer(input, variantToUse);
  return new Uint8Array(result);
};
exports.from_base64 = from_base64;
const to_base64 = (input, variant) => {
  const variantToUse = variant || _libsodiumJsUtils.base64_variants.URLSAFE_NO_PADDING;
  if (typeof input === 'string') {
    return global.jsi_to_base64_from_string(input, variantToUse);
  } else {
    return global.jsi_to_base64_from_arraybuffer(input.buffer, variantToUse);
  }
};
exports.to_base64 = to_base64;
function to_hex(input) {
  if (typeof input === 'string') {
    return global.jsi_to_hex_from_string(input);
  } else {
    return global.jsi_to_hex_from_arraybuffer(input.buffer);
  }
}
function randombytes_buf(length, outputFormat) {
  const result = global.jsi_randombytes_buf(length);
  return (0, _utils.convertToOutputFormat)(result, outputFormat);
}
function randombytes_uniform(upper_bound) {
  return global.jsi_randombytes_uniform(upper_bound);
}
function crypto_secretbox_keygen(outputFormat) {
  const result = global.jsi_crypto_secretbox_keygen();
  return (0, _utils.convertToOutputFormat)(result, outputFormat);
}
function crypto_aead_xchacha20poly1305_ietf_keygen(outputFormat) {
  const result = global.jsi_crypto_aead_xchacha20poly1305_ietf_keygen();
  return (0, _utils.convertToOutputFormat)(result, outputFormat);
}
function crypto_kdf_keygen(outputFormat) {
  const result = global.jsi_crypto_kdf_keygen();
  return (0, _utils.convertToOutputFormat)(result, outputFormat);
}
function crypto_box_keypair(outputFormat) {
  const result = global.jsi_crypto_box_keypair();
  return {
    keyType: 'curve25519',
    publicKey: (0, _utils.convertToOutputFormat)(result.publicKey, outputFormat),
    privateKey: (0, _utils.convertToOutputFormat)(result.secretKey, outputFormat)
  };
}
function crypto_sign_keypair(outputFormat) {
  const result = global.jsi_crypto_sign_keypair();
  return {
    keyType: 'ed25519',
    publicKey: (0, _utils.convertToOutputFormat)(result.publicKey, outputFormat),
    privateKey: (0, _utils.convertToOutputFormat)(result.secretKey, outputFormat)
  };
}
function crypto_sign_detached(message, privateKey, outputFormat) {
  let result;
  if (typeof message === 'string') {
    result = global.jsi_crypto_sign_keypair_from_string(message, privateKey.buffer);
  } else {
    result = global.jsi_crypto_sign_keypair_from_arraybuffer(message.buffer, privateKey.buffer);
  }
  return (0, _utils.convertToOutputFormat)(result, outputFormat);
}
function crypto_sign_verify_detached(signature, message, publicKey) {
  let result;
  if (typeof message === 'string') {
    result = global.jsi_crypto_sign_verify_detached_from_string(signature.buffer, message, publicKey.buffer);
  } else {
    result = global.jsi_crypto_sign_verify_detached_from_arraybuffer(signature.buffer, message.buffer, publicKey.buffer);
  }
  return result;
}
function crypto_secretbox_easy(message, nonce, key, outputFormat) {
  let result;
  if (typeof message === 'string') {
    result = global.jsi_crypto_secretbox_easy_from_string(message, nonce.buffer, key.buffer);
  } else {
    result = global.jsi_crypto_secretbox_easy_from_arraybuffer(message.buffer, nonce.buffer, key.buffer);
  }
  return (0, _utils.convertToOutputFormat)(result, outputFormat);
}
function crypto_secretbox_open_easy(ciphertext, nonce, key, outputFormat) {
  let result;
  if (typeof ciphertext === 'string') {
    result = global.jsi_crypto_secretbox_open_easy_from_string(ciphertext, nonce.buffer, key.buffer);
  } else {
    result = global.jsi_crypto_secretbox_open_easy_from_arraybuffer(ciphertext.buffer, nonce.buffer, key.buffer);
  }
  return (0, _utils.convertToOutputFormat)(result, outputFormat);
}
function crypto_box_easy(message, nonce, publicKey, privateKey, outputFormat) {
  let result;
  if (typeof message === 'string') {
    result = global.jsi_crypto_box_easy_from_string(message, nonce.buffer, publicKey.buffer, privateKey.buffer);
  } else {
    result = global.jsi_crypto_box_easy_from_arraybuffer(message.buffer, nonce.buffer, publicKey.buffer, privateKey.buffer);
  }
  return (0, _utils.convertToOutputFormat)(result, outputFormat);
}
function crypto_box_open_easy(ciphertext, nonce, publicKey, privateKey, outputFormat) {
  let result;
  if (typeof ciphertext === 'string') {
    result = global.jsi_crypto_box_open_easy_from_string(ciphertext, nonce.buffer, publicKey.buffer, privateKey.buffer);
  } else {
    result = global.jsi_crypto_box_open_easy_from_arraybuffer(ciphertext.buffer, nonce.buffer, publicKey.buffer, privateKey.buffer);
  }
  return (0, _utils.convertToOutputFormat)(result, outputFormat);
}
function crypto_pwhash(keyLength, password, salt, opsLimit, memLimit, algorithm, outputFormat) {
  let result;
  if (typeof password === 'string') {
    result = global.jsi_crypto_pwhash_from_string(keyLength, password, salt.buffer, opsLimit, memLimit, algorithm);
  } else {
    result = global.jsi_crypto_pwhash_from_arraybuffer(keyLength, password.buffer, salt.buffer, opsLimit, memLimit, algorithm);
  }
  return (0, _utils.convertToOutputFormat)(result, outputFormat);
}
function crypto_kdf_derive_from_key(subkey_len, subkey_id, ctx, key, outputFormat) {
  const result = global.jsi_crypto_kdf_derive_from_key(subkey_len, subkey_id, ctx, key.buffer);
  return (0, _utils.convertToOutputFormat)(result, outputFormat);
}
function crypto_aead_xchacha20poly1305_ietf_encrypt(message, additional_data, _secret_nonce, public_nonce, key, outputFormat) {
  let result;
  if (typeof message === 'string' && typeof additional_data === 'string') {
    result = global.jsi_crypto_aead_xchacha20poly1305_ietf_encrypt_from_string(message, additional_data, public_nonce.buffer, key.buffer);
  } else if (typeof message !== 'string' && typeof additional_data === 'string') {
    result = global.jsi_crypto_aead_xchacha20poly1305_ietf_encrypt_from_arraybuffer(message.buffer, additional_data, public_nonce.buffer, key.buffer);
  } else {
    throw new Error('crypto_aead_xchacha20poly1305_ietf_encrypt: input type not yet implemented');
  }
  return (0, _utils.convertToOutputFormat)(result, outputFormat);
}
function crypto_aead_xchacha20poly1305_ietf_decrypt(_secret_nonce, ciphertext, additional_data, public_nonce, key, outputFormat) {
  let result;
  if (typeof ciphertext !== 'string' && typeof additional_data === 'string') {
    result = global.jsi_crypto_aead_xchacha20poly1305_ietf_decrypt_from_arraybuffer(ciphertext.buffer, additional_data, public_nonce.buffer, key.buffer);
  } else {
    throw new Error('crypto_aead_xchacha20poly1305_ietf_decrypt: input type not yet implemented');
  }
  return (0, _utils.convertToOutputFormat)(result, outputFormat);
}

// add no-op ready to match the libsodium-wrappers API
const ready = new Promise(resolve => resolve());
exports.ready = ready;
var _default = {
  crypto_aead_xchacha20poly1305_ietf_decrypt,
  crypto_aead_xchacha20poly1305_ietf_encrypt,
  crypto_aead_xchacha20poly1305_ietf_KEYBYTES,
  crypto_aead_xchacha20poly1305_ietf_keygen,
  crypto_aead_xchacha20poly1305_ietf_NPUBBYTES,
  crypto_box_easy,
  crypto_box_keypair,
  crypto_box_NONCEBYTES,
  crypto_box_open_easy,
  crypto_box_PUBLICKEYBYTES,
  crypto_box_SECRETKEYBYTES,
  crypto_kdf_derive_from_key,
  crypto_kdf_CONTEXTBYTES,
  crypto_kdf_KEYBYTES,
  crypto_kdf_keygen,
  crypto_pwhash,
  crypto_pwhash_ALG_DEFAULT,
  crypto_pwhash_BYTES_MAX,
  crypto_pwhash_BYTES_MIN,
  crypto_pwhash_MEMLIMIT_INTERACTIVE,
  crypto_pwhash_OPSLIMIT_INTERACTIVE,
  crypto_pwhash_SALTBYTES,
  crypto_secretbox_easy,
  crypto_secretbox_KEYBYTES,
  crypto_secretbox_keygen,
  crypto_secretbox_NONCEBYTES,
  crypto_secretbox_open_easy,
  crypto_sign_detached,
  crypto_sign_keypair,
  crypto_sign_verify_detached,
  from_base64,
  randombytes_buf,
  randombytes_uniform,
  ready,
  to_base64,
  to_hex,
  to_string: _libsodiumJsUtils.to_string
};
exports.default = _default;
//# sourceMappingURL=index.js.map