From 52bbb6aa0ecc35106d68ef65eb6e5ecefe065ff2 Mon Sep 17 00:00:00 2001 From: Yu-huan Kuo Date: Sun, 6 Oct 2024 01:56:58 +0800 Subject: [PATCH] feat: use Wasm to compute email addr --- pages/index.vue | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index 0204a2b..4f3fc23 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -78,12 +78,23 @@ import VueWriter from 'vue-writer' import { SOCIAL_LINKS } from '@/config/links' -const arr = [ - 0x64, 0x47, 0x39, 0x31, 0x59, 0x32, 0x68, 0x41, 0x63, 0x6d, 0x35, 0x74, 0x5a, 0x57, 0x39, 0x33, - 0x4c, 0x6d, 0x4e, 0x76, 0x62, 0x51, 0x3d, 0x3d -] if (process.client) { - localStorage.setItem('email', atob(String.fromCharCode.apply(null, arr))) + const { instance } = await WebAssembly.instantiate( + new Uint8Array([ + 0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 127, 3, 3, 2, 0, 0, 5, 3, 1, 0, 1, 7, 44, 3, + 6, 109, 101, 109, 111, 114, 121, 2, 0, 14, 103, 101, 116, 95, 115, 116, 114, 105, 110, 103, + 95, 112, 116, 114, 0, 0, 14, 103, 101, 116, 95, 115, 116, 114, 105, 110, 103, 95, 108, 101, + 110, 0, 1, 10, 11, 2, 4, 0, 65, 0, 11, 4, 0, 65, 16, 11, 11, 22, 1, 0, 65, 0, 11, 16, 116, + 111, 117, 99, 104, 64, 114, 110, 109, 101, 111, 119, 46, 99, 111, 109 + ]) + ) + + const memory = instance.exports.memory as WebAssembly.Memory + const ptr = (instance.exports.get_string_ptr as CallableFunction)() as number + const len = (instance.exports.get_string_len as CallableFunction)() as number + const arr = new Uint8Array(memory.buffer, ptr, len) + + localStorage.setItem('email', String.fromCharCode.apply(null, Array.from(arr))) } const emailAddr = ref('')