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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Decode one tile from RGBA pixel data. Returns raw stego bytes (TILE_CAP).
|
| 3 |
+
* @param {Uint8Array} rgba
|
| 4 |
+
* @returns {Uint8Array}
|
| 5 |
+
*/
|
| 6 |
+
export function decode_tile(rgba) {
|
| 7 |
+
const ptr0 = passArray8ToWasm0(rgba, wasm.__wbindgen_malloc);
|
| 8 |
+
const len0 = WASM_VECTOR_LEN;
|
| 9 |
+
const ret = wasm.decode_tile(ptr0, len0);
|
| 10 |
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
| 11 |
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
| 12 |
+
return v2;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
/**
|
| 16 |
+
* Extract a named segment from the payload. Returns empty vec if not found.
|
| 17 |
+
* @param {Uint8Array} all_bytes
|
| 18 |
+
* @param {string} name
|
| 19 |
+
* @returns {Uint8Array}
|
| 20 |
+
*/
|
| 21 |
+
export function extract_segment(all_bytes, name) {
|
| 22 |
+
const ptr0 = passArray8ToWasm0(all_bytes, wasm.__wbindgen_malloc);
|
| 23 |
+
const len0 = WASM_VECTOR_LEN;
|
| 24 |
+
const ptr1 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
| 25 |
+
const len1 = WASM_VECTOR_LEN;
|
| 26 |
+
const ret = wasm.extract_segment(ptr0, len0, ptr1, len1);
|
| 27 |
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
| 28 |
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
| 29 |
+
return v3;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
/**
|
| 33 |
+
* Reconstruct NFT7 payload from concatenated tile bytes.
|
| 34 |
+
* Returns JSON: {"segments":[{"name":"wav","size":123},...], "wav_offset":N, "wav_size":N}
|
| 35 |
+
* @param {Uint8Array} all_bytes
|
| 36 |
+
* @returns {string}
|
| 37 |
+
*/
|
| 38 |
+
export function reconstruct_payload(all_bytes) {
|
| 39 |
+
let deferred2_0;
|
| 40 |
+
let deferred2_1;
|
| 41 |
+
try {
|
| 42 |
+
const ptr0 = passArray8ToWasm0(all_bytes, wasm.__wbindgen_malloc);
|
| 43 |
+
const len0 = WASM_VECTOR_LEN;
|
| 44 |
+
const ret = wasm.reconstruct_payload(ptr0, len0);
|
| 45 |
+
deferred2_0 = ret[0];
|
| 46 |
+
deferred2_1 = ret[1];
|
| 47 |
+
return getStringFromWasm0(ret[0], ret[1]);
|
| 48 |
+
} finally {
|
| 49 |
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
function __wbg_get_imports() {
|
| 54 |
+
const import0 = {
|
| 55 |
+
__proto__: null,
|
| 56 |
+
__wbindgen_init_externref_table: function() {
|
| 57 |
+
const table = wasm.__wbindgen_externrefs;
|
| 58 |
+
const offset = table.grow(4);
|
| 59 |
+
table.set(0, undefined);
|
| 60 |
+
table.set(offset + 0, undefined);
|
| 61 |
+
table.set(offset + 1, null);
|
| 62 |
+
table.set(offset + 2, true);
|
| 63 |
+
table.set(offset + 3, false);
|
| 64 |
+
},
|
| 65 |
+
};
|
| 66 |
+
return {
|
| 67 |
+
__proto__: null,
|
| 68 |
+
"./stego_bg.js": import0,
|
| 69 |
+
};
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
function getArrayU8FromWasm0(ptr, len) {
|
| 73 |
+
ptr = ptr >>> 0;
|
| 74 |
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
function getStringFromWasm0(ptr, len) {
|
| 78 |
+
ptr = ptr >>> 0;
|
| 79 |
+
return decodeText(ptr, len);
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
let cachedUint8ArrayMemory0 = null;
|
| 83 |
+
function getUint8ArrayMemory0() {
|
| 84 |
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
| 85 |
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
| 86 |
+
}
|
| 87 |
+
return cachedUint8ArrayMemory0;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
function passArray8ToWasm0(arg, malloc) {
|
| 91 |
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
| 92 |
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
| 93 |
+
WASM_VECTOR_LEN = arg.length;
|
| 94 |
+
return ptr;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
function passStringToWasm0(arg, malloc, realloc) {
|
| 98 |
+
if (realloc === undefined) {
|
| 99 |
+
const buf = cachedTextEncoder.encode(arg);
|
| 100 |
+
const ptr = malloc(buf.length, 1) >>> 0;
|
| 101 |
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
| 102 |
+
WASM_VECTOR_LEN = buf.length;
|
| 103 |
+
return ptr;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
let len = arg.length;
|
| 107 |
+
let ptr = malloc(len, 1) >>> 0;
|
| 108 |
+
|
| 109 |
+
const mem = getUint8ArrayMemory0();
|
| 110 |
+
|
| 111 |
+
let offset = 0;
|
| 112 |
+
|
| 113 |
+
for (; offset < len; offset++) {
|
| 114 |
+
const code = arg.charCodeAt(offset);
|
| 115 |
+
if (code > 0x7F) break;
|
| 116 |
+
mem[ptr + offset] = code;
|
| 117 |
+
}
|
| 118 |
+
if (offset !== len) {
|
| 119 |
+
if (offset !== 0) {
|
| 120 |
+
arg = arg.slice(offset);
|
| 121 |
+
}
|
| 122 |
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
| 123 |
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
| 124 |
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
| 125 |
+
|
| 126 |
+
offset += ret.written;
|
| 127 |
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
WASM_VECTOR_LEN = offset;
|
| 131 |
+
return ptr;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
| 135 |
+
cachedTextDecoder.decode();
|
| 136 |
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
| 137 |
+
let numBytesDecoded = 0;
|
| 138 |
+
function decodeText(ptr, len) {
|
| 139 |
+
numBytesDecoded += len;
|
| 140 |
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
| 141 |
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
| 142 |
+
cachedTextDecoder.decode();
|
| 143 |
+
numBytesDecoded = len;
|
| 144 |
+
}
|
| 145 |
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
const cachedTextEncoder = new TextEncoder();
|
| 149 |
+
|
| 150 |
+
if (!('encodeInto' in cachedTextEncoder)) {
|
| 151 |
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
| 152 |
+
const buf = cachedTextEncoder.encode(arg);
|
| 153 |
+
view.set(buf);
|
| 154 |
+
return {
|
| 155 |
+
read: arg.length,
|
| 156 |
+
written: buf.length
|
| 157 |
+
};
|
| 158 |
+
};
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
let WASM_VECTOR_LEN = 0;
|
| 162 |
+
|
| 163 |
+
let wasmModule, wasm;
|
| 164 |
+
function __wbg_finalize_init(instance, module) {
|
| 165 |
+
wasm = instance.exports;
|
| 166 |
+
wasmModule = module;
|
| 167 |
+
cachedUint8ArrayMemory0 = null;
|
| 168 |
+
wasm.__wbindgen_start();
|
| 169 |
+
return wasm;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
async function __wbg_load(module, imports) {
|
| 173 |
+
if (typeof Response === 'function' && module instanceof Response) {
|
| 174 |
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
| 175 |
+
try {
|
| 176 |
+
return await WebAssembly.instantiateStreaming(module, imports);
|
| 177 |
+
} catch (e) {
|
| 178 |
+
const validResponse = module.ok && expectedResponseType(module.type);
|
| 179 |
+
|
| 180 |
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
| 181 |
+
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);
|
| 182 |
+
|
| 183 |
+
} else { throw e; }
|
| 184 |
+
}
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
const bytes = await module.arrayBuffer();
|
| 188 |
+
return await WebAssembly.instantiate(bytes, imports);
|
| 189 |
+
} else {
|
| 190 |
+
const instance = await WebAssembly.instantiate(module, imports);
|
| 191 |
+
|
| 192 |
+
if (instance instanceof WebAssembly.Instance) {
|
| 193 |
+
return { instance, module };
|
| 194 |
+
} else {
|
| 195 |
+
return instance;
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
function expectedResponseType(type) {
|
| 200 |
+
switch (type) {
|
| 201 |
+
case 'basic': case 'cors': case 'default': return true;
|
| 202 |
+
}
|
| 203 |
+
return false;
|
| 204 |
+
}
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
function initSync(module) {
|
| 208 |
+
if (wasm !== undefined) return wasm;
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
if (module !== undefined) {
|
| 212 |
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
| 213 |
+
({module} = module)
|
| 214 |
+
} else {
|
| 215 |
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
| 216 |
+
}
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
const imports = __wbg_get_imports();
|
| 220 |
+
if (!(module instanceof WebAssembly.Module)) {
|
| 221 |
+
module = new WebAssembly.Module(module);
|
| 222 |
+
}
|
| 223 |
+
const instance = new WebAssembly.Instance(module, imports);
|
| 224 |
+
return __wbg_finalize_init(instance, module);
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
async function __wbg_init(module_or_path) {
|
| 228 |
+
if (wasm !== undefined) return wasm;
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
if (module_or_path !== undefined) {
|
| 232 |
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
| 233 |
+
({module_or_path} = module_or_path)
|
| 234 |
+
} else {
|
| 235 |
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
| 236 |
+
}
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
if (module_or_path === undefined) {
|
| 240 |
+
module_or_path = new URL('stego_bg.wasm', import.meta.url);
|
| 241 |
+
}
|
| 242 |
+
const imports = __wbg_get_imports();
|
| 243 |
+
|
| 244 |
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
| 245 |
+
module_or_path = fetch(module_or_path);
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
| 249 |
+
|
| 250 |
+
return __wbg_finalize_init(instance, module);
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
export { initSync, __wbg_init as default };
|
pkg/pkg/stego_bg.wasm
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d5a519dba94313be3757d29621765140d619d83a04b6124c37b64c93364bf130
|
| 3 |
+
size 31709
|