@eduarte/chc 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,19 +6,20 @@ Browser-side decryption package for `/api/ccus/history` protected payloads.
6
6
 
7
7
  ```bash
8
8
  cd wasm/ccu-history-crypto
9
- ./scripts/build.sh
9
+ ./scripts/build.sh "your-arbitrary-key-string"
10
10
  ```
11
11
 
12
12
  ## Usage
13
13
 
14
14
  ```js
15
15
  import { decryptCcuHistoryPayload } from './pkg/index.js';
16
+ import wasmUrl from './pkg/ccu_history_crypto.wasm?url'; // Vite-style
16
17
 
17
18
  const encrypted = await fetch('https://api.citizenshub.app/api/ccus/history').then((r) => r.json());
18
19
 
19
20
  const history = await decryptCcuHistoryPayload(encrypted, {
20
- key: import.meta.env.VITE_CCU_HISTORY_ENCRYPTION_KEY,
21
- url: window.location.href
21
+ url: window.location.href,
22
+ wasmUrl
22
23
  });
23
24
  ```
24
25
 
@@ -28,8 +29,9 @@ const history = await decryptCcuHistoryPayload(encrypted, {
28
29
  - Uses wasm-exported `is_allowed_origin` to enforce host check for `citizenshub.app`.
29
30
  - Supports deterministic payloads (no random salt/nonce rotation), so encrypted response can be cached.
30
31
  - Supports optional `gzip` decompression when payload has `compression: "gzip"`.
31
- - Accepts arbitrary-length key material and derives a 16-byte working key via `SHA-256`.
32
- - Key input formats:
32
+ - Build step accepts arbitrary-length key material and derives a 16-byte working key via `SHA-256` (same as backend).
33
+ - `wasmUrl` can be provided at runtime to avoid bundler/static-path issues.
34
+ - Key input formats for `build.sh`:
33
35
  - Raw passphrase string (any length)
34
36
  - `hex:<even-length-hex>`
35
37
  - `base64:<base64 or base64url>`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eduarte/chc",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "sideEffects": false,
package/pkg/chc.js ADDED
@@ -0,0 +1,16 @@
1
+
2
+ var Module = (() => {
3
+ var _scriptName = import.meta.url;
4
+
5
+ return (
6
+ function(moduleArg = {}) {
7
+ var moduleRtn;
8
+
9
+ var Module=moduleArg;var readyPromiseResolve,readyPromiseReject;var readyPromise=new Promise((resolve,reject)=>{readyPromiseResolve=resolve;readyPromiseReject=reject});var ENVIRONMENT_IS_WEB=true;var ENVIRONMENT_IS_WORKER=false;var moduleOverrides=Object.assign({},Module);var arguments_=[];var thisProgram="./this.program";var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){if(ENVIRONMENT_IS_WORKER){scriptDirectory=self.location.href}else if(typeof document!="undefined"&&document.currentScript){scriptDirectory=document.currentScript.src}if(_scriptName){scriptDirectory=_scriptName}if(scriptDirectory.startsWith("blob:")){scriptDirectory=""}else{scriptDirectory=scriptDirectory.substr(0,scriptDirectory.replace(/[?#].*/,"").lastIndexOf("/")+1)}{readAsync=url=>fetch(url,{credentials:"same-origin"}).then(response=>{if(response.ok){return response.arrayBuffer()}return Promise.reject(new Error(response.status+" : "+response.url))})}}else{}var out=Module["print"]||console.log.bind(console);var err=Module["printErr"]||console.error.bind(console);Object.assign(Module,moduleOverrides);moduleOverrides=null;if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];var wasmBinary=Module["wasmBinary"];var wasmMemory;var ABORT=false;var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;function updateMemoryViews(){var b=wasmMemory.buffer;Module["HEAP8"]=HEAP8=new Int8Array(b);Module["HEAP16"]=HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);Module["HEAPU16"]=HEAPU16=new Uint16Array(b);Module["HEAP32"]=HEAP32=new Int32Array(b);Module["HEAPU32"]=HEAPU32=new Uint32Array(b);Module["HEAPF32"]=HEAPF32=new Float32Array(b);Module["HEAPF64"]=HEAPF64=new Float64Array(b)}var __ATPRERUN__=[];var __ATINIT__=[];var __ATPOSTRUN__=[];var runtimeInitialized=false;function preRun(){var preRuns=Module["preRun"];if(preRuns){if(typeof preRuns=="function")preRuns=[preRuns];preRuns.forEach(addOnPreRun)}callRuntimeCallbacks(__ATPRERUN__)}function initRuntime(){runtimeInitialized=true;callRuntimeCallbacks(__ATINIT__)}function postRun(){var postRuns=Module["postRun"];if(postRuns){if(typeof postRuns=="function")postRuns=[postRuns];postRuns.forEach(addOnPostRun)}callRuntimeCallbacks(__ATPOSTRUN__)}function addOnPreRun(cb){__ATPRERUN__.unshift(cb)}function addOnInit(cb){__ATINIT__.unshift(cb)}function addOnPostRun(cb){__ATPOSTRUN__.unshift(cb)}var runDependencies=0;var runDependencyWatcher=null;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;Module["monitorRunDependencies"]?.(runDependencies)}function removeRunDependency(id){runDependencies--;Module["monitorRunDependencies"]?.(runDependencies);if(runDependencies==0){if(runDependencyWatcher!==null){clearInterval(runDependencyWatcher);runDependencyWatcher=null}if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}}function abort(what){Module["onAbort"]?.(what);what="Aborted("+what+")";err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);readyPromiseReject(e);throw e}var dataURIPrefix="data:application/octet-stream;base64,";var isDataURI=filename=>filename.startsWith(dataURIPrefix);function findWasmBinary(){if(Module["locateFile"]){var f="chc.wasm";if(!isDataURI(f)){return locateFile(f)}return f}return new URL("chc.wasm",import.meta.url).href}var wasmBinaryFile;function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}function getBinaryPromise(binaryFile){if(!wasmBinary){return readAsync(binaryFile).then(response=>new Uint8Array(response),()=>getBinarySync(binaryFile))}return Promise.resolve().then(()=>getBinarySync(binaryFile))}function instantiateArrayBuffer(binaryFile,imports,receiver){return getBinaryPromise(binaryFile).then(binary=>WebAssembly.instantiate(binary,imports)).then(receiver,reason=>{err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)})}function instantiateAsync(binary,binaryFile,imports,callback){if(!binary&&typeof WebAssembly.instantiateStreaming=="function"&&!isDataURI(binaryFile)&&typeof fetch=="function"){return fetch(binaryFile,{credentials:"same-origin"}).then(response=>{var result=WebAssembly.instantiateStreaming(response,imports);return result.then(callback,function(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation");return instantiateArrayBuffer(binaryFile,imports,callback)})})}return instantiateArrayBuffer(binaryFile,imports,callback)}function getWasmImports(){return{a:wasmImports}}function createWasm(){var info=getWasmImports();function receiveInstance(instance,module){wasmExports=instance.exports;wasmMemory=wasmExports["b"];updateMemoryViews();addOnInit(wasmExports["c"]);removeRunDependency("wasm-instantiate");return wasmExports}addRunDependency("wasm-instantiate");function receiveInstantiationResult(result){receiveInstance(result["instance"])}if(Module["instantiateWasm"]){try{return Module["instantiateWasm"](info,receiveInstance)}catch(e){err(`Module.instantiateWasm callback failed with error: ${e}`);readyPromiseReject(e)}}wasmBinaryFile??=findWasmBinary();instantiateAsync(wasmBinary,wasmBinaryFile,info,receiveInstantiationResult).catch(readyPromiseReject);return{}}var callRuntimeCallbacks=callbacks=>{callbacks.forEach(f=>f(Module))};var noExitRuntime=Module["noExitRuntime"]||true;var abortOnCannotGrowMemory=requestedSize=>{abort("OOM")};var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;abortOnCannotGrowMemory(requestedSize)};var lengthBytesUTF8=str=>{var len=0;for(var i=0;i<str.length;++i){var c=str.charCodeAt(i);if(c<=127){len++}else if(c<=2047){len+=2}else if(c>=55296&&c<=57343){len+=4;++i}else{len+=3}}return len};var stringToUTF8Array=(str,heap,outIdx,maxBytesToWrite)=>{if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i<str.length;++i){var u=str.charCodeAt(i);if(u>=55296&&u<=57343){var u1=str.charCodeAt(++i);u=65536+((u&1023)<<10)|u1&1023}if(u<=127){if(outIdx>=endIdx)break;heap[outIdx++]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;heap[outIdx++]=192|u>>6;heap[outIdx++]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;heap[outIdx++]=224|u>>12;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}else{if(outIdx+3>=endIdx)break;heap[outIdx++]=240|u>>18;heap[outIdx++]=128|u>>12&63;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}}heap[outIdx]=0;return outIdx-startIdx};var stringToUTF8=(str,outPtr,maxBytesToWrite)=>stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite);var wasmImports={a:_emscripten_resize_heap};var wasmExports=createWasm();var ___wasm_call_ctors=()=>(___wasm_call_ctors=wasmExports["c"])();var _is_allowed_origin=Module["_is_allowed_origin"]=(a0,a1)=>(_is_allowed_origin=Module["_is_allowed_origin"]=wasmExports["d"])(a0,a1);var _xtea_ctr_crypt=Module["_xtea_ctr_crypt"]=(a0,a1,a2,a3,a4)=>(_xtea_ctr_crypt=Module["_xtea_ctr_crypt"]=wasmExports["e"])(a0,a1,a2,a3,a4);var _xtea_ctr_crypt_build_key=Module["_xtea_ctr_crypt_build_key"]=(a0,a1,a2,a3)=>(_xtea_ctr_crypt_build_key=Module["_xtea_ctr_crypt_build_key"]=wasmExports["f"])(a0,a1,a2,a3);var _malloc=Module["_malloc"]=a0=>(_malloc=Module["_malloc"]=wasmExports["h"])(a0);var _free=Module["_free"]=a0=>(_free=Module["_free"]=wasmExports["i"])(a0);Module["stringToUTF8"]=stringToUTF8;Module["lengthBytesUTF8"]=lengthBytesUTF8;var calledRun;var calledPrerun;dependenciesFulfilled=function runCaller(){if(!calledRun)run();if(!calledRun)dependenciesFulfilled=runCaller};function run(){if(runDependencies>0){return}if(!calledPrerun){calledPrerun=1;preRun();if(runDependencies>0){return}}function doRun(){if(calledRun)return;calledRun=1;Module["calledRun"]=1;if(ABORT)return;initRuntime();readyPromiseResolve(Module);Module["onRuntimeInitialized"]?.();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(()=>{setTimeout(()=>Module["setStatus"](""),1);doRun()},1)}else{doRun()}}if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()()}}run();moduleRtn=readyPromise;
10
+
11
+
12
+ return moduleRtn;
13
+ }
14
+ );
15
+ })();
16
+ export default Module;
package/pkg/chc.wasm ADDED
Binary file
package/pkg/index.d.ts CHANGED
@@ -8,13 +8,13 @@ export interface EncryptedCcuHistoryPayload {
8
8
  }
9
9
 
10
10
  export interface DecryptOptions {
11
- key: string;
12
11
  url?: string;
12
+ wasmUrl?: string;
13
13
  }
14
14
 
15
- export function assertCitizensHubOrigin(url: string): Promise<boolean>;
15
+ export function assertCitizensHubOrigin(url: string, options?: DecryptOptions): Promise<boolean>;
16
16
 
17
17
  export function decryptCcuHistoryPayload<T = unknown>(
18
18
  encryptedPayload: EncryptedCcuHistoryPayload | T,
19
- options?: Partial<DecryptOptions>
19
+ options?: DecryptOptions
20
20
  ): Promise<T>;
package/pkg/index.js CHANGED
@@ -1,21 +1,39 @@
1
1
  import initWasmModule from './ccu_history_crypto.js';
2
2
 
3
- const XTEA_KEY_BYTES = 16;
4
3
  const XTEA_NONCE_BYTES = 8;
5
4
  const ALGORITHM = 'xtea-ctr-v1';
6
5
 
7
6
  let wasmModulePromise;
7
+ let wasmBinaryUrl;
8
+
9
+ async function getWasmModule(options = {}) {
10
+ if (typeof options.wasmUrl === 'string' && options.wasmUrl.trim()) {
11
+ const normalizedUrl = options.wasmUrl.trim();
12
+ if (wasmBinaryUrl && wasmBinaryUrl !== normalizedUrl) {
13
+ throw new Error('WASM already initialized with a different wasmUrl.');
14
+ }
15
+ wasmBinaryUrl = normalizedUrl;
16
+ }
8
17
 
9
- async function getWasmModule() {
10
18
  if (!wasmModulePromise) {
11
- wasmModulePromise = initWasmModule();
19
+ wasmModulePromise = initWasmModule({
20
+ locateFile: (path, scriptDirectory) => {
21
+ if (path.endsWith('.wasm') && wasmBinaryUrl) {
22
+ return wasmBinaryUrl;
23
+ }
24
+ if (scriptDirectory) {
25
+ return `${scriptDirectory}${path}`;
26
+ }
27
+ return new URL(path, import.meta.url).href;
28
+ }
29
+ });
12
30
  }
13
31
 
14
32
  return wasmModulePromise;
15
33
  }
16
34
 
17
- export async function assertCitizensHubOrigin(url) {
18
- const wasmModule = await getWasmModule();
35
+ export async function assertCitizensHubOrigin(url, options = {}) {
36
+ const wasmModule = await getWasmModule(options);
19
37
  return isAllowedOrigin(wasmModule, url);
20
38
  }
21
39
 
@@ -33,7 +51,6 @@ export async function decryptCcuHistoryPayload(encryptedPayload, options = {}) {
33
51
  throw new Error('Missing current URL. Pass options.url when running outside browser context.');
34
52
  }
35
53
 
36
- const key = await deriveEncryptionKey(options.key);
37
54
  const nonce = decodeBase64Url(encryptedPayload.nonce);
38
55
  const ciphertext = decodeBase64Url(encryptedPayload.payload);
39
56
 
@@ -41,36 +58,32 @@ export async function decryptCcuHistoryPayload(encryptedPayload, options = {}) {
41
58
  throw new Error(`Nonce must decode to ${XTEA_NONCE_BYTES} bytes.`);
42
59
  }
43
60
 
44
- const wasmModule = await getWasmModule();
61
+ const wasmModule = await getWasmModule(options);
45
62
 
46
63
  if (!isAllowedOrigin(wasmModule, currentUrl)) {
47
64
  throw new Error('Origin not allowed. Decryption is restricted to citizenshub.app.');
48
65
  }
49
66
 
50
- const decryptedBytes = transformWithWasm(wasmModule, ciphertext, key, nonce);
67
+ const decryptedBytes = transformWithWasm(wasmModule, ciphertext, nonce);
51
68
  const plaintextBytes = await maybeDecompress(decryptedBytes, encryptedPayload.compression);
52
69
  const plaintext = new TextDecoder().decode(plaintextBytes);
53
70
 
54
71
  return JSON.parse(plaintext);
55
72
  }
56
73
 
57
- function transformWithWasm(wasmModule, input, key, nonce) {
74
+ function transformWithWasm(wasmModule, input, nonce) {
58
75
  const inputPtr = wasmModule._malloc(input.length);
59
- const keyPtr = wasmModule._malloc(key.length);
60
76
  const noncePtr = wasmModule._malloc(nonce.length);
61
77
  const outputPtr = wasmModule._malloc(input.length);
62
78
 
63
79
  try {
64
80
  wasmModule.HEAPU8.set(input, inputPtr);
65
- wasmModule.HEAPU8.set(key, keyPtr);
66
81
  wasmModule.HEAPU8.set(nonce, noncePtr);
67
-
68
- wasmModule._xtea_ctr_crypt(inputPtr, input.length, keyPtr, noncePtr, outputPtr);
82
+ wasmModule._xtea_ctr_crypt_build_key(inputPtr, input.length, noncePtr, outputPtr);
69
83
 
70
84
  return wasmModule.HEAPU8.slice(outputPtr, outputPtr + input.length);
71
85
  } finally {
72
86
  wasmModule._free(inputPtr);
73
- wasmModule._free(keyPtr);
74
87
  wasmModule._free(noncePtr);
75
88
  wasmModule._free(outputPtr);
76
89
  }
@@ -88,37 +101,6 @@ function isAllowedOrigin(wasmModule, url) {
88
101
  }
89
102
  }
90
103
 
91
- async function deriveEncryptionKey(value) {
92
- if (!value || typeof value !== 'string') {
93
- throw new Error('Missing encryption key. Pass options.key.');
94
- }
95
-
96
- const trimmed = value.trim();
97
- if (!trimmed) {
98
- throw new Error('Encryption key cannot be empty.');
99
- }
100
-
101
- const keyMaterial = decodeKeyMaterial(trimmed);
102
- const digest = await crypto.subtle.digest('SHA-256', keyMaterial);
103
- return new Uint8Array(digest).slice(0, XTEA_KEY_BYTES);
104
- }
105
-
106
- function decodeKeyMaterial(value) {
107
- if (value.startsWith('hex:')) {
108
- const hex = value.slice(4);
109
- if (!/^[0-9a-fA-F]+$/.test(hex) || hex.length % 2 !== 0) {
110
- throw new Error('Invalid hex key material after hex:.');
111
- }
112
- return hexToBytes(hex);
113
- }
114
-
115
- if (value.startsWith('base64:')) {
116
- return decodeBase64Url(value.slice(7));
117
- }
118
-
119
- return new TextEncoder().encode(value);
120
- }
121
-
122
104
  async function maybeDecompress(bytes, compression) {
123
105
  if (!compression || compression === 'none') {
124
106
  return bytes;
@@ -140,14 +122,6 @@ async function maybeDecompress(bytes, compression) {
140
122
  return new Uint8Array(await new Response(stream.readable).arrayBuffer());
141
123
  }
142
124
 
143
- function hexToBytes(value) {
144
- const bytes = new Uint8Array(value.length / 2);
145
- for (let i = 0; i < value.length; i += 2) {
146
- bytes[i / 2] = parseInt(value.slice(i, i + 2), 16);
147
- }
148
- return bytes;
149
- }
150
-
151
125
  function decodeBase64Url(value) {
152
126
  const normalized = value.replace(/-/g, '+').replace(/_/g, '/');
153
127
  const padded = normalized + '='.repeat((4 - (normalized.length % 4)) % 4);
@@ -1,16 +0,0 @@
1
-
2
- var Module = (() => {
3
- var _scriptName = import.meta.url;
4
-
5
- return (
6
- function(moduleArg = {}) {
7
- var moduleRtn;
8
-
9
- var Module=moduleArg;var readyPromiseResolve,readyPromiseReject;var readyPromise=new Promise((resolve,reject)=>{readyPromiseResolve=resolve;readyPromiseReject=reject});var ENVIRONMENT_IS_WEB=true;var ENVIRONMENT_IS_WORKER=false;var moduleOverrides=Object.assign({},Module);var arguments_=[];var thisProgram="./this.program";var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){if(ENVIRONMENT_IS_WORKER){scriptDirectory=self.location.href}else if(typeof document!="undefined"&&document.currentScript){scriptDirectory=document.currentScript.src}if(_scriptName){scriptDirectory=_scriptName}if(scriptDirectory.startsWith("blob:")){scriptDirectory=""}else{scriptDirectory=scriptDirectory.substr(0,scriptDirectory.replace(/[?#].*/,"").lastIndexOf("/")+1)}{readAsync=url=>fetch(url,{credentials:"same-origin"}).then(response=>{if(response.ok){return response.arrayBuffer()}return Promise.reject(new Error(response.status+" : "+response.url))})}}else{}var out=Module["print"]||console.log.bind(console);var err=Module["printErr"]||console.error.bind(console);Object.assign(Module,moduleOverrides);moduleOverrides=null;if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];var wasmBinary=Module["wasmBinary"];var wasmMemory;var ABORT=false;var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;function updateMemoryViews(){var b=wasmMemory.buffer;Module["HEAP8"]=HEAP8=new Int8Array(b);Module["HEAP16"]=HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);Module["HEAPU16"]=HEAPU16=new Uint16Array(b);Module["HEAP32"]=HEAP32=new Int32Array(b);Module["HEAPU32"]=HEAPU32=new Uint32Array(b);Module["HEAPF32"]=HEAPF32=new Float32Array(b);Module["HEAPF64"]=HEAPF64=new Float64Array(b)}var __ATPRERUN__=[];var __ATINIT__=[];var __ATPOSTRUN__=[];var runtimeInitialized=false;function preRun(){var preRuns=Module["preRun"];if(preRuns){if(typeof preRuns=="function")preRuns=[preRuns];preRuns.forEach(addOnPreRun)}callRuntimeCallbacks(__ATPRERUN__)}function initRuntime(){runtimeInitialized=true;callRuntimeCallbacks(__ATINIT__)}function postRun(){var postRuns=Module["postRun"];if(postRuns){if(typeof postRuns=="function")postRuns=[postRuns];postRuns.forEach(addOnPostRun)}callRuntimeCallbacks(__ATPOSTRUN__)}function addOnPreRun(cb){__ATPRERUN__.unshift(cb)}function addOnInit(cb){__ATINIT__.unshift(cb)}function addOnPostRun(cb){__ATPOSTRUN__.unshift(cb)}var runDependencies=0;var runDependencyWatcher=null;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;Module["monitorRunDependencies"]?.(runDependencies)}function removeRunDependency(id){runDependencies--;Module["monitorRunDependencies"]?.(runDependencies);if(runDependencies==0){if(runDependencyWatcher!==null){clearInterval(runDependencyWatcher);runDependencyWatcher=null}if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}}function abort(what){Module["onAbort"]?.(what);what="Aborted("+what+")";err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);readyPromiseReject(e);throw e}var dataURIPrefix="data:application/octet-stream;base64,";var isDataURI=filename=>filename.startsWith(dataURIPrefix);function findWasmBinary(){if(Module["locateFile"]){var f="ccu_history_crypto.wasm";if(!isDataURI(f)){return locateFile(f)}return f}return new URL("ccu_history_crypto.wasm",import.meta.url).href}var wasmBinaryFile;function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}function getBinaryPromise(binaryFile){if(!wasmBinary){return readAsync(binaryFile).then(response=>new Uint8Array(response),()=>getBinarySync(binaryFile))}return Promise.resolve().then(()=>getBinarySync(binaryFile))}function instantiateArrayBuffer(binaryFile,imports,receiver){return getBinaryPromise(binaryFile).then(binary=>WebAssembly.instantiate(binary,imports)).then(receiver,reason=>{err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)})}function instantiateAsync(binary,binaryFile,imports,callback){if(!binary&&typeof WebAssembly.instantiateStreaming=="function"&&!isDataURI(binaryFile)&&typeof fetch=="function"){return fetch(binaryFile,{credentials:"same-origin"}).then(response=>{var result=WebAssembly.instantiateStreaming(response,imports);return result.then(callback,function(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation");return instantiateArrayBuffer(binaryFile,imports,callback)})})}return instantiateArrayBuffer(binaryFile,imports,callback)}function getWasmImports(){return{a:wasmImports}}function createWasm(){var info=getWasmImports();function receiveInstance(instance,module){wasmExports=instance.exports;wasmMemory=wasmExports["b"];updateMemoryViews();addOnInit(wasmExports["c"]);removeRunDependency("wasm-instantiate");return wasmExports}addRunDependency("wasm-instantiate");function receiveInstantiationResult(result){receiveInstance(result["instance"])}if(Module["instantiateWasm"]){try{return Module["instantiateWasm"](info,receiveInstance)}catch(e){err(`Module.instantiateWasm callback failed with error: ${e}`);readyPromiseReject(e)}}wasmBinaryFile??=findWasmBinary();instantiateAsync(wasmBinary,wasmBinaryFile,info,receiveInstantiationResult).catch(readyPromiseReject);return{}}var callRuntimeCallbacks=callbacks=>{callbacks.forEach(f=>f(Module))};var noExitRuntime=Module["noExitRuntime"]||true;var abortOnCannotGrowMemory=requestedSize=>{abort("OOM")};var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;abortOnCannotGrowMemory(requestedSize)};var lengthBytesUTF8=str=>{var len=0;for(var i=0;i<str.length;++i){var c=str.charCodeAt(i);if(c<=127){len++}else if(c<=2047){len+=2}else if(c>=55296&&c<=57343){len+=4;++i}else{len+=3}}return len};var stringToUTF8Array=(str,heap,outIdx,maxBytesToWrite)=>{if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i<str.length;++i){var u=str.charCodeAt(i);if(u>=55296&&u<=57343){var u1=str.charCodeAt(++i);u=65536+((u&1023)<<10)|u1&1023}if(u<=127){if(outIdx>=endIdx)break;heap[outIdx++]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;heap[outIdx++]=192|u>>6;heap[outIdx++]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;heap[outIdx++]=224|u>>12;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}else{if(outIdx+3>=endIdx)break;heap[outIdx++]=240|u>>18;heap[outIdx++]=128|u>>12&63;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}}heap[outIdx]=0;return outIdx-startIdx};var stringToUTF8=(str,outPtr,maxBytesToWrite)=>stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite);var wasmImports={a:_emscripten_resize_heap};var wasmExports=createWasm();var ___wasm_call_ctors=()=>(___wasm_call_ctors=wasmExports["c"])();var _is_allowed_origin=Module["_is_allowed_origin"]=(a0,a1)=>(_is_allowed_origin=Module["_is_allowed_origin"]=wasmExports["d"])(a0,a1);var _xtea_ctr_crypt=Module["_xtea_ctr_crypt"]=(a0,a1,a2,a3,a4)=>(_xtea_ctr_crypt=Module["_xtea_ctr_crypt"]=wasmExports["e"])(a0,a1,a2,a3,a4);var _malloc=Module["_malloc"]=a0=>(_malloc=Module["_malloc"]=wasmExports["g"])(a0);var _free=Module["_free"]=a0=>(_free=Module["_free"]=wasmExports["h"])(a0);Module["stringToUTF8"]=stringToUTF8;Module["lengthBytesUTF8"]=lengthBytesUTF8;var calledRun;var calledPrerun;dependenciesFulfilled=function runCaller(){if(!calledRun)run();if(!calledRun)dependenciesFulfilled=runCaller};function run(){if(runDependencies>0){return}if(!calledPrerun){calledPrerun=1;preRun();if(runDependencies>0){return}}function doRun(){if(calledRun)return;calledRun=1;Module["calledRun"]=1;if(ABORT)return;initRuntime();readyPromiseResolve(Module);Module["onRuntimeInitialized"]?.();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(()=>{setTimeout(()=>Module["setStatus"](""),1);doRun()},1)}else{doRun()}}if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()()}}run();moduleRtn=readyPromise;
10
-
11
-
12
- return moduleRtn;
13
- }
14
- );
15
- })();
16
- export default Module;
Binary file