;(async function () {
function sendMessage(message) {
window.parent.postMessage(message, '*')
}
const aesGcmKeyRaw = new Uint8Array(__TEMPLATE_runtime_aes_gcm_key__)
const aesGcmKey = await window.crypto.subtle.importKey(
'raw',
aesGcmKeyRaw,
'AES-GCM',
true,
['encrypt']
)
async function encrypt(data) {
let algorithm = Object.create(null)
algorithm.name = 'AES-GCM'
algorithm.iv = window.crypto.getRandomValues(new Uint8Array(12))
let encoder = new TextEncoder()
let payloadRaw = encoder.encode(__RAW_stringify_ipc_message_fn__(data))
return window.crypto.subtle
.encrypt(algorithm, aesGcmKey, payloadRaw)
.then((payload) => {
let result = Object.create(null)
result.nonce = Array.from(new Uint8Array(algorithm.iv))
result.payload = Array.from(new Uint8Array(payload))
return result
})
}
function isIsolationPayload(event) {
return (
typeof event.data === 'object' &&
'callback' in event.data &&
'error' in event.data
)
}
async function payloadHandler(event) {
if (!isIsolationPayload(event)) {
return
}
let data = event.data
if (typeof window.__TAURI_ISOLATION_HOOK__ === 'function') {
data = await window.__TAURI_ISOLATION_HOOK__(data)
}
const encrypted = await encrypt(data)
sendMessage(encrypted)
}
window.addEventListener('message', payloadHandler, false)
const readyIntervalMs = 50
function waitUntilReady() {
if (
typeof window.__TAURI_ISOLATION_HOOK__ === 'function' ||
window.__TAURI_ISOLATION_HOOK__ === null
) {
sendMessage('__TAURI_ISOLATION_READY__')
} else {
setTimeout(waitUntilReady, readyIntervalMs)
}
}
setTimeout(waitUntilReady, readyIntervalMs)
})()