let wasm;

const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );

if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };

let cachedUint8ArrayMemory0 = null;

function getUint8ArrayMemory0() {
    if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
        cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
    }
    return cachedUint8ArrayMemory0;
}

function getStringFromWasm0(ptr, len) {
    ptr = ptr >>> 0;
    return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
}

const heap = new Array(128).fill(undefined);

heap.push(undefined, null, true, false);

let heap_next = heap.length;

function addHeapObject(obj) {
    if (heap_next === heap.length) heap.push(heap.length + 1);
    const idx = heap_next;
    heap_next = heap[idx];

    heap[idx] = obj;
    return idx;
}

let cachedDataViewMemory0 = null;

function getDataViewMemory0() {
    if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
        cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
    }
    return cachedDataViewMemory0;
}
/**
 * @returns {string}
 */
export function mysterion_version() {
    let deferred1_0;
    let deferred1_1;
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        wasm.mysterion_version(retptr);
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        deferred1_0 = r0;
        deferred1_1 = r1;
        return getStringFromWasm0(r0, r1);
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
        wasm.__wbindgen_export_0(deferred1_0, deferred1_1, 1);
    }
}

/**
 * @returns {boolean}
 */
export function mysterion_selftest() {
    const ret = wasm.mysterion_selftest();
    return ret !== 0;
}

let WASM_VECTOR_LEN = 0;

const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );

const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
    ? function (arg, view) {
    return cachedTextEncoder.encodeInto(arg, view);
}
    : function (arg, view) {
    const buf = cachedTextEncoder.encode(arg);
    view.set(buf);
    return {
        read: arg.length,
        written: buf.length
    };
});

function passStringToWasm0(arg, malloc, realloc) {

    if (realloc === undefined) {
        const buf = cachedTextEncoder.encode(arg);
        const ptr = malloc(buf.length, 1) >>> 0;
        getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
        WASM_VECTOR_LEN = buf.length;
        return ptr;
    }

    let len = arg.length;
    let ptr = malloc(len, 1) >>> 0;

    const mem = getUint8ArrayMemory0();

    let offset = 0;

    for (; offset < len; offset++) {
        const code = arg.charCodeAt(offset);
        if (code > 0x7F) break;
        mem[ptr + offset] = code;
    }

    if (offset !== len) {
        if (offset !== 0) {
            arg = arg.slice(offset);
        }
        ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
        const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
        const ret = encodeString(arg, view);

        offset += ret.written;
        ptr = realloc(ptr, len, offset, 1) >>> 0;
    }

    WASM_VECTOR_LEN = offset;
    return ptr;
}

function passArray8ToWasm0(arg, malloc) {
    const ptr = malloc(arg.length * 1, 1) >>> 0;
    getUint8ArrayMemory0().set(arg, ptr / 1);
    WASM_VECTOR_LEN = arg.length;
    return ptr;
}

function getObject(idx) { return heap[idx]; }

function dropObject(idx) {
    if (idx < 132) return;
    heap[idx] = heap_next;
    heap_next = idx;
}

function takeObject(idx) {
    const ret = getObject(idx);
    dropObject(idx);
    return ret;
}

let cachedUint32ArrayMemory0 = null;

function getUint32ArrayMemory0() {
    if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
        cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
    }
    return cachedUint32ArrayMemory0;
}

function getArrayU32FromWasm0(ptr, len) {
    ptr = ptr >>> 0;
    return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
}
/**
 * Derive the keyframe selection map for a video with `total_keyframes`
 * candidate keyframes under the given density.
 *
 * Returns a Uint32Array of selected indices sorted ascending, or throws on
 * any validation failure.
 * @param {string} version
 * @param {Uint8Array} raw_blake3
 * @param {string} creator_id
 * @param {Uint8Array} rfc3161_der
 * @param {Uint8Array} steg_id
 * @param {number} total_keyframes
 * @param {number} density_numerator
 * @param {number} density_denominator
 * @returns {Uint32Array}
 */
export function mysterion_keyframe_map(version, raw_blake3, creator_id, rfc3161_der, steg_id, total_keyframes, density_numerator, density_denominator) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        const ptr0 = passStringToWasm0(version, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
        const len0 = WASM_VECTOR_LEN;
        const ptr1 = passArray8ToWasm0(raw_blake3, wasm.__wbindgen_export_1);
        const len1 = WASM_VECTOR_LEN;
        const ptr2 = passStringToWasm0(creator_id, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
        const len2 = WASM_VECTOR_LEN;
        const ptr3 = passArray8ToWasm0(rfc3161_der, wasm.__wbindgen_export_1);
        const len3 = WASM_VECTOR_LEN;
        const ptr4 = passArray8ToWasm0(steg_id, wasm.__wbindgen_export_1);
        const len4 = WASM_VECTOR_LEN;
        wasm.mysterion_keyframe_map(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, total_keyframes, density_numerator, density_denominator);
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
        if (r3) {
            throw takeObject(r2);
        }
        var v6 = getArrayU32FromWasm0(r0, r1).slice();
        wasm.__wbindgen_export_0(r0, r1 * 4, 4);
        return v6;
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

function getArrayU8FromWasm0(ptr, len) {
    ptr = ptr >>> 0;
    return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
}
/**
 * Build the 256-bit DCT-SS payload (v5.5.81 production schema).  Returns 32 bytes:
 * [0..16] raw 128-bit creator UUID, [16..32] BLAKE3-derived signing nonce.
 * @param {string} version
 * @param {Uint8Array} raw_blake3
 * @param {string} creator_id
 * @param {Uint8Array} rfc3161_der
 * @param {Uint8Array} steg_id
 * @returns {Uint8Array}
 */
export function mysterion_dct_ss_build_payload(version, raw_blake3, creator_id, rfc3161_der, steg_id) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        const ptr0 = passStringToWasm0(version, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
        const len0 = WASM_VECTOR_LEN;
        const ptr1 = passArray8ToWasm0(raw_blake3, wasm.__wbindgen_export_1);
        const len1 = WASM_VECTOR_LEN;
        const ptr2 = passStringToWasm0(creator_id, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
        const len2 = WASM_VECTOR_LEN;
        const ptr3 = passArray8ToWasm0(rfc3161_der, wasm.__wbindgen_export_1);
        const len3 = WASM_VECTOR_LEN;
        const ptr4 = passArray8ToWasm0(steg_id, wasm.__wbindgen_export_1);
        const len4 = WASM_VECTOR_LEN;
        wasm.mysterion_dct_ss_build_payload(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4);
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
        if (r3) {
            throw takeObject(r2);
        }
        var v6 = getArrayU8FromWasm0(r0, r1).slice();
        wasm.__wbindgen_export_0(r0, r1 * 1, 1);
        return v6;
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * Embed the 80-byte payload into a Y-plane. Takes ownership of `y_plane`,
 * modifies it in place, and returns the mutated plane.
 * @param {string} version
 * @param {Uint8Array} raw_blake3
 * @param {string} creator_id
 * @param {Uint8Array} rfc3161_der
 * @param {Uint8Array} steg_id
 * @param {Uint8Array} y_plane
 * @param {number} width
 * @param {number} height
 * @param {Uint8Array} payload_bytes
 * @param {number} strength
 * @param {number} chip_rate
 * @returns {Uint8Array}
 */
export function mysterion_dct_ss_embed(version, raw_blake3, creator_id, rfc3161_der, steg_id, y_plane, width, height, payload_bytes, strength, chip_rate) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        const ptr0 = passStringToWasm0(version, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
        const len0 = WASM_VECTOR_LEN;
        const ptr1 = passArray8ToWasm0(raw_blake3, wasm.__wbindgen_export_1);
        const len1 = WASM_VECTOR_LEN;
        const ptr2 = passStringToWasm0(creator_id, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
        const len2 = WASM_VECTOR_LEN;
        const ptr3 = passArray8ToWasm0(rfc3161_der, wasm.__wbindgen_export_1);
        const len3 = WASM_VECTOR_LEN;
        const ptr4 = passArray8ToWasm0(steg_id, wasm.__wbindgen_export_1);
        const len4 = WASM_VECTOR_LEN;
        const ptr5 = passArray8ToWasm0(y_plane, wasm.__wbindgen_export_1);
        const len5 = WASM_VECTOR_LEN;
        const ptr6 = passArray8ToWasm0(payload_bytes, wasm.__wbindgen_export_1);
        const len6 = WASM_VECTOR_LEN;
        wasm.mysterion_dct_ss_embed(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5, width, height, ptr6, len6, strength, chip_rate);
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
        if (r3) {
            throw takeObject(r2);
        }
        var v8 = getArrayU8FromWasm0(r0, r1).slice();
        wasm.__wbindgen_export_0(r0, r1 * 1, 1);
        return v8;
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * Extract the 80-byte payload from a Y-plane.
 * @param {string} version
 * @param {Uint8Array} raw_blake3
 * @param {string} creator_id
 * @param {Uint8Array} rfc3161_der
 * @param {Uint8Array} steg_id
 * @param {Uint8Array} y_plane
 * @param {number} width
 * @param {number} height
 * @param {number} chip_rate
 * @returns {Uint8Array}
 */
export function mysterion_dct_ss_extract(version, raw_blake3, creator_id, rfc3161_der, steg_id, y_plane, width, height, chip_rate) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        const ptr0 = passStringToWasm0(version, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
        const len0 = WASM_VECTOR_LEN;
        const ptr1 = passArray8ToWasm0(raw_blake3, wasm.__wbindgen_export_1);
        const len1 = WASM_VECTOR_LEN;
        const ptr2 = passStringToWasm0(creator_id, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
        const len2 = WASM_VECTOR_LEN;
        const ptr3 = passArray8ToWasm0(rfc3161_der, wasm.__wbindgen_export_1);
        const len3 = WASM_VECTOR_LEN;
        const ptr4 = passArray8ToWasm0(steg_id, wasm.__wbindgen_export_1);
        const len4 = WASM_VECTOR_LEN;
        const ptr5 = passArray8ToWasm0(y_plane, wasm.__wbindgen_export_1);
        const len5 = WASM_VECTOR_LEN;
        wasm.mysterion_dct_ss_extract(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5, width, height, chip_rate);
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
        if (r3) {
            throw takeObject(r2);
        }
        var v7 = getArrayU8FromWasm0(r0, r1).slice();
        wasm.__wbindgen_export_0(r0, r1 * 1, 1);
        return v7;
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

let cachedUint16ArrayMemory0 = null;

function getUint16ArrayMemory0() {
    if (cachedUint16ArrayMemory0 === null || cachedUint16ArrayMemory0.byteLength === 0) {
        cachedUint16ArrayMemory0 = new Uint16Array(wasm.memory.buffer);
    }
    return cachedUint16ArrayMemory0;
}

function passArray16ToWasm0(arg, malloc) {
    const ptr = malloc(arg.length * 2, 2) >>> 0;
    getUint16ArrayMemory0().set(arg, ptr / 2);
    WASM_VECTOR_LEN = arg.length;
    return ptr;
}
/**
 * Explicit-block-list DCT-SS extract. Mirrors the FFI
 * `mysterion_dct_ss_extract_explicit` (used by the desktop app): instead of
 * re-deriving the block list from the marked image — which is content-
 * sensitive and diverges from the signer's list on natural photographs after
 * re-encoding — the caller passes the signer's stored `dct_block_list`
 * (fetched from /verify/prepare as `dct_block_list_b64`). `blocks` is a flat
 * Uint16Array of raster-order (bx, by) pairs: [bx0, by0, bx1, by1, …].
 * @param {string} version
 * @param {Uint8Array} raw_blake3
 * @param {string} creator_id
 * @param {Uint8Array} rfc3161_der
 * @param {Uint8Array} steg_id
 * @param {Uint8Array} y_plane
 * @param {number} width
 * @param {number} height
 * @param {number} chip_rate
 * @param {Uint16Array} blocks
 * @returns {Uint8Array}
 */
export function mysterion_dct_ss_extract_explicit(version, raw_blake3, creator_id, rfc3161_der, steg_id, y_plane, width, height, chip_rate, blocks) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        const ptr0 = passStringToWasm0(version, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
        const len0 = WASM_VECTOR_LEN;
        const ptr1 = passArray8ToWasm0(raw_blake3, wasm.__wbindgen_export_1);
        const len1 = WASM_VECTOR_LEN;
        const ptr2 = passStringToWasm0(creator_id, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
        const len2 = WASM_VECTOR_LEN;
        const ptr3 = passArray8ToWasm0(rfc3161_der, wasm.__wbindgen_export_1);
        const len3 = WASM_VECTOR_LEN;
        const ptr4 = passArray8ToWasm0(steg_id, wasm.__wbindgen_export_1);
        const len4 = WASM_VECTOR_LEN;
        const ptr5 = passArray8ToWasm0(y_plane, wasm.__wbindgen_export_1);
        const len5 = WASM_VECTOR_LEN;
        const ptr6 = passArray16ToWasm0(blocks, wasm.__wbindgen_export_1);
        const len6 = WASM_VECTOR_LEN;
        wasm.mysterion_dct_ss_extract_explicit(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5, width, height, chip_rate, ptr6, len6);
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
        if (r3) {
            throw takeObject(r2);
        }
        var v8 = getArrayU8FromWasm0(r0, r1).slice();
        wasm.__wbindgen_export_0(r0, r1 * 1, 1);
        return v8;
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * Application-layer payload reconciliation. Recovers the LDPC residual
 * 1-2-bit error floor by trying 0/1/2-bit flips and validating each
 * candidate against its recomputed BLAKE3 nonce.
 *
 * Returns the corrected 32-byte payload, or throws if no candidate within
 * 2-bit Hamming distance has a valid manifest.
 * @param {Uint8Array} extracted_payload
 * @param {string} version
 * @param {Uint8Array} raw_blake3
 * @param {string} creator_id
 * @param {Uint8Array} rfc3161_der
 * @param {Uint8Array} steg_id
 * @returns {Uint8Array}
 */
export function mysterion_payload_reconcile(extracted_payload, version, raw_blake3, creator_id, rfc3161_der, steg_id) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        const ptr0 = passArray8ToWasm0(extracted_payload, wasm.__wbindgen_export_1);
        const len0 = WASM_VECTOR_LEN;
        const ptr1 = passStringToWasm0(version, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
        const len1 = WASM_VECTOR_LEN;
        const ptr2 = passArray8ToWasm0(raw_blake3, wasm.__wbindgen_export_1);
        const len2 = WASM_VECTOR_LEN;
        const ptr3 = passStringToWasm0(creator_id, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
        const len3 = WASM_VECTOR_LEN;
        const ptr4 = passArray8ToWasm0(rfc3161_der, wasm.__wbindgen_export_1);
        const len4 = WASM_VECTOR_LEN;
        const ptr5 = passArray8ToWasm0(steg_id, wasm.__wbindgen_export_1);
        const len5 = WASM_VECTOR_LEN;
        wasm.mysterion_payload_reconcile(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5);
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
        if (r3) {
            throw takeObject(r2);
        }
        var v7 = getArrayU8FromWasm0(r0, r1).slice();
        wasm.__wbindgen_export_0(r0, r1 * 1, 1);
        return v7;
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * Pick the appropriate DCT-SS chip rate for an input given its count of
 * usable mid-band 8×8 blocks. Returns 256 (production) or 64 (fallback).
 * @param {number} usable_blocks
 * @returns {number}
 */
export function mysterion_chip_rate_for(usable_blocks) {
    const ret = wasm.mysterion_chip_rate_for(usable_blocks);
    return ret >>> 0;
}

/**
 * Embed the 32-byte payload into LSBs of `y_plane` at PRNG-selected positions.
 * @param {string} version
 * @param {Uint8Array} raw_blake3
 * @param {string} creator_id
 * @param {Uint8Array} rfc3161_der
 * @param {Uint8Array} steg_id
 * @param {Uint8Array} y_plane
 * @param {number} width
 * @param {number} height
 * @param {Uint8Array} payload_bytes
 * @returns {Uint8Array}
 */
export function mysterion_lsb_embed(version, raw_blake3, creator_id, rfc3161_der, steg_id, y_plane, width, height, payload_bytes) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        const ptr0 = passStringToWasm0(version, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
        const len0 = WASM_VECTOR_LEN;
        const ptr1 = passArray8ToWasm0(raw_blake3, wasm.__wbindgen_export_1);
        const len1 = WASM_VECTOR_LEN;
        const ptr2 = passStringToWasm0(creator_id, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
        const len2 = WASM_VECTOR_LEN;
        const ptr3 = passArray8ToWasm0(rfc3161_der, wasm.__wbindgen_export_1);
        const len3 = WASM_VECTOR_LEN;
        const ptr4 = passArray8ToWasm0(steg_id, wasm.__wbindgen_export_1);
        const len4 = WASM_VECTOR_LEN;
        const ptr5 = passArray8ToWasm0(y_plane, wasm.__wbindgen_export_1);
        const len5 = WASM_VECTOR_LEN;
        const ptr6 = passArray8ToWasm0(payload_bytes, wasm.__wbindgen_export_1);
        const len6 = WASM_VECTOR_LEN;
        wasm.mysterion_lsb_embed(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5, width, height, ptr6, len6);
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
        if (r3) {
            throw takeObject(r2);
        }
        var v8 = getArrayU8FromWasm0(r0, r1).slice();
        wasm.__wbindgen_export_0(r0, r1 * 1, 1);
        return v8;
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * Extract the 32-byte payload from LSBs of `y_plane`.
 * @param {string} version
 * @param {Uint8Array} raw_blake3
 * @param {string} creator_id
 * @param {Uint8Array} rfc3161_der
 * @param {Uint8Array} steg_id
 * @param {Uint8Array} y_plane
 * @param {number} width
 * @param {number} height
 * @returns {Uint8Array}
 */
export function mysterion_lsb_extract(version, raw_blake3, creator_id, rfc3161_der, steg_id, y_plane, width, height) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        const ptr0 = passStringToWasm0(version, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
        const len0 = WASM_VECTOR_LEN;
        const ptr1 = passArray8ToWasm0(raw_blake3, wasm.__wbindgen_export_1);
        const len1 = WASM_VECTOR_LEN;
        const ptr2 = passStringToWasm0(creator_id, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
        const len2 = WASM_VECTOR_LEN;
        const ptr3 = passArray8ToWasm0(rfc3161_der, wasm.__wbindgen_export_1);
        const len3 = WASM_VECTOR_LEN;
        const ptr4 = passArray8ToWasm0(steg_id, wasm.__wbindgen_export_1);
        const len4 = WASM_VECTOR_LEN;
        const ptr5 = passArray8ToWasm0(y_plane, wasm.__wbindgen_export_1);
        const len5 = WASM_VECTOR_LEN;
        wasm.mysterion_lsb_extract(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5, width, height);
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
        if (r3) {
            throw takeObject(r2);
        }
        var v7 = getArrayU8FromWasm0(r0, r1).slice();
        wasm.__wbindgen_export_0(r0, r1 * 1, 1);
        return v7;
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * Embed a watermark into an RGB888 frame.
 *
 * `rgb` is `width * height * 3` bytes. Width and height must be even.
 * Returns a new Uint8Array of the same length with the watermark applied.
 * Throws on validation failure or below-tier rejection.
 * @param {Uint8Array} rgb
 * @param {number} width
 * @param {number} height
 * @param {string} version
 * @param {Uint8Array} raw_blake3
 * @param {string} creator_id
 * @param {Uint8Array} rfc3161_der
 * @param {Uint8Array} steg_id
 * @param {Uint8Array} payload
 * @returns {Uint8Array}
 */
export function mysterion_v2_embed_image(rgb, width, height, version, raw_blake3, creator_id, rfc3161_der, steg_id, payload) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        const ptr0 = passArray8ToWasm0(rgb, wasm.__wbindgen_export_1);
        const len0 = WASM_VECTOR_LEN;
        const ptr1 = passStringToWasm0(version, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
        const len1 = WASM_VECTOR_LEN;
        const ptr2 = passArray8ToWasm0(raw_blake3, wasm.__wbindgen_export_1);
        const len2 = WASM_VECTOR_LEN;
        const ptr3 = passStringToWasm0(creator_id, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
        const len3 = WASM_VECTOR_LEN;
        const ptr4 = passArray8ToWasm0(rfc3161_der, wasm.__wbindgen_export_1);
        const len4 = WASM_VECTOR_LEN;
        const ptr5 = passArray8ToWasm0(steg_id, wasm.__wbindgen_export_1);
        const len5 = WASM_VECTOR_LEN;
        const ptr6 = passArray8ToWasm0(payload, wasm.__wbindgen_export_1);
        const len6 = WASM_VECTOR_LEN;
        wasm.mysterion_v2_embed_image(retptr, ptr0, len0, width, height, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6);
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
        if (r3) {
            throw takeObject(r2);
        }
        var v8 = getArrayU8FromWasm0(r0, r1).slice();
        wasm.__wbindgen_export_0(r0, r1 * 1, 1);
        return v8;
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * Verify a watermark in an RGB888 frame.
 * @param {Uint8Array} rgb
 * @param {number} width
 * @param {number} height
 * @param {number} expected_width
 * @param {number} expected_height
 * @param {string} version
 * @param {Uint8Array} raw_blake3
 * @param {string} creator_id
 * @param {Uint8Array} rfc3161_der
 * @param {Uint8Array} steg_id
 * @returns {MysterionV2VerifyResult}
 */
export function mysterion_v2_verify_image(rgb, width, height, expected_width, expected_height, version, raw_blake3, creator_id, rfc3161_der, steg_id) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        const ptr0 = passArray8ToWasm0(rgb, wasm.__wbindgen_export_1);
        const len0 = WASM_VECTOR_LEN;
        const ptr1 = passStringToWasm0(version, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
        const len1 = WASM_VECTOR_LEN;
        const ptr2 = passArray8ToWasm0(raw_blake3, wasm.__wbindgen_export_1);
        const len2 = WASM_VECTOR_LEN;
        const ptr3 = passStringToWasm0(creator_id, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
        const len3 = WASM_VECTOR_LEN;
        const ptr4 = passArray8ToWasm0(rfc3161_der, wasm.__wbindgen_export_1);
        const len4 = WASM_VECTOR_LEN;
        const ptr5 = passArray8ToWasm0(steg_id, wasm.__wbindgen_export_1);
        const len5 = WASM_VECTOR_LEN;
        wasm.mysterion_v2_verify_image(retptr, ptr0, len0, width, height, expected_width, expected_height, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5);
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        if (r2) {
            throw takeObject(r1);
        }
        return MysterionV2VerifyResult.__wrap(r0);
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * Verify across multiple video frames with soft-combining.
 *
 * `frames_rgb` is a contiguous Uint8Array of `frame_count` concatenated
 * RGB888 frames of identical size, total length
 * `frame_count * width * height * 3`.
 * @param {Uint8Array} frames_rgb
 * @param {number} frame_count
 * @param {number} width
 * @param {number} height
 * @param {number} expected_width
 * @param {number} expected_height
 * @param {string} version
 * @param {Uint8Array} raw_blake3
 * @param {string} creator_id
 * @param {Uint8Array} rfc3161_der
 * @param {Uint8Array} steg_id
 * @returns {MysterionV2VerifyResult}
 */
export function mysterion_v2_verify_video(frames_rgb, frame_count, width, height, expected_width, expected_height, version, raw_blake3, creator_id, rfc3161_der, steg_id) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        const ptr0 = passArray8ToWasm0(frames_rgb, wasm.__wbindgen_export_1);
        const len0 = WASM_VECTOR_LEN;
        const ptr1 = passStringToWasm0(version, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
        const len1 = WASM_VECTOR_LEN;
        const ptr2 = passArray8ToWasm0(raw_blake3, wasm.__wbindgen_export_1);
        const len2 = WASM_VECTOR_LEN;
        const ptr3 = passStringToWasm0(creator_id, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
        const len3 = WASM_VECTOR_LEN;
        const ptr4 = passArray8ToWasm0(rfc3161_der, wasm.__wbindgen_export_1);
        const len4 = WASM_VECTOR_LEN;
        const ptr5 = passArray8ToWasm0(steg_id, wasm.__wbindgen_export_1);
        const len5 = WASM_VECTOR_LEN;
        wasm.mysterion_v2_verify_video(retptr, ptr0, len0, frame_count, width, height, expected_width, expected_height, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5);
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        if (r2) {
            throw takeObject(r1);
        }
        return MysterionV2VerifyResult.__wrap(r0);
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

const MysterionV2VerifyResultFinalization = (typeof FinalizationRegistry === 'undefined')
    ? { register: () => {}, unregister: () => {} }
    : new FinalizationRegistry(ptr => wasm.__wbg_mysterionv2verifyresult_free(ptr >>> 0, 1));
/**
 * Result of a v2 verify call.
 */
export class MysterionV2VerifyResult {

    static __wrap(ptr) {
        ptr = ptr >>> 0;
        const obj = Object.create(MysterionV2VerifyResult.prototype);
        obj.__wbg_ptr = ptr;
        MysterionV2VerifyResultFinalization.register(obj, obj.__wbg_ptr, obj);
        return obj;
    }

    __destroy_into_raw() {
        const ptr = this.__wbg_ptr;
        this.__wbg_ptr = 0;
        MysterionV2VerifyResultFinalization.unregister(this);
        return ptr;
    }

    free() {
        const ptr = this.__destroy_into_raw();
        wasm.__wbg_mysterionv2verifyresult_free(ptr, 0);
    }
    /**
     * True if the LDPC decoder converged on a payload candidate.
     * @returns {boolean}
     */
    get decoded() {
        const ret = wasm.mysterionv2verifyresult_decoded(this.__wbg_ptr);
        return ret !== 0;
    }
    /**
     * 32-byte payload if `decoded` is true; empty otherwise.
     * @returns {Uint8Array}
     */
    get payload() {
        try {
            const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
            wasm.mysterionv2verifyresult_payload(retptr, this.__wbg_ptr);
            var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
            var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
            var v1 = getArrayU8FromWasm0(r0, r1).slice();
            wasm.__wbindgen_export_0(r0, r1 * 1, 1);
            return v1;
        } finally {
            wasm.__wbindgen_add_to_stack_pointer(16);
        }
    }
    /**
     * 0..3 for Deg0..Deg270; only meaningful when `decoded` is true.
     * @returns {number}
     */
    get orientation() {
        const ret = wasm.mysterionv2verifyresult_orientation(this.__wbg_ptr);
        return ret >>> 0;
    }
    /**
     * True if the frame was below the minimum embed resolution (Tier::Tiny).
     * In that case, `decoded` is false; the caller should treat the absence
     * as "watermark not detected" rather than a failure.
     * @returns {boolean}
     */
    get belowMinResolution() {
        const ret = wasm.mysterionv2verifyresult_belowMinResolution(this.__wbg_ptr);
        return ret !== 0;
    }
}

async function __wbg_load(module, imports) {
    if (typeof Response === 'function' && module instanceof Response) {
        if (typeof WebAssembly.instantiateStreaming === 'function') {
            try {
                return await WebAssembly.instantiateStreaming(module, imports);

            } catch (e) {
                if (module.headers.get('Content-Type') != 'application/wasm') {
                    console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);

                } else {
                    throw e;
                }
            }
        }

        const bytes = await module.arrayBuffer();
        return await WebAssembly.instantiate(bytes, imports);

    } else {
        const instance = await WebAssembly.instantiate(module, imports);

        if (instance instanceof WebAssembly.Instance) {
            return { instance, module };

        } else {
            return instance;
        }
    }
}

function __wbg_get_imports() {
    const imports = {};
    imports.wbg = {};
    imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
        const ret = new Error(getStringFromWasm0(arg0, arg1));
        return addHeapObject(ret);
    };
    imports.wbg.__wbindgen_throw = function(arg0, arg1) {
        throw new Error(getStringFromWasm0(arg0, arg1));
    };

    return imports;
}

function __wbg_init_memory(imports, memory) {

}

function __wbg_finalize_init(instance, module) {
    wasm = instance.exports;
    __wbg_init.__wbindgen_wasm_module = module;
    cachedDataViewMemory0 = null;
    cachedUint16ArrayMemory0 = null;
    cachedUint32ArrayMemory0 = null;
    cachedUint8ArrayMemory0 = null;



    return wasm;
}

function initSync(module) {
    if (wasm !== undefined) return wasm;


    if (typeof module !== 'undefined') {
        if (Object.getPrototypeOf(module) === Object.prototype) {
            ({module} = module)
        } else {
            console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
        }
    }

    const imports = __wbg_get_imports();

    __wbg_init_memory(imports);

    if (!(module instanceof WebAssembly.Module)) {
        module = new WebAssembly.Module(module);
    }

    const instance = new WebAssembly.Instance(module, imports);

    return __wbg_finalize_init(instance, module);
}

async function __wbg_init(module_or_path) {
    if (wasm !== undefined) return wasm;


    if (typeof module_or_path !== 'undefined') {
        if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
            ({module_or_path} = module_or_path)
        } else {
            console.warn('using deprecated parameters for the initialization function; pass a single object instead')
        }
    }

    if (typeof module_or_path === 'undefined') {
        module_or_path = new URL('mysterion_native_bg.wasm', import.meta.url);
    }
    const imports = __wbg_get_imports();

    if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
        module_or_path = fetch(module_or_path);
    }

    __wbg_init_memory(imports);

    const { instance, module } = await __wbg_load(await module_or_path, imports);

    return __wbg_finalize_init(instance, module);
}

export { initSync };
export default __wbg_init;
