You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

91 lines
2.8 KiB

importScripts("https://cdn.jsdelivr.net/npm/tweetnacl-util@0.15.1/nacl-util.min.js");
importScripts("https://cdnjs.cloudflare.com/ajax/libs/tweetnacl/1.0.2/nacl.min.js");
importScripts("https://cdn.jsdelivr.net/npm/@sphereon/did-jwt/build/index.min.js");
self.addEventListener("push", function (event) {
let payload;
if (event.data) {
payload = JSON.parse(event.data.text());
}
const title = payload ? payload.title : "Custom Title";
const options = {
body: payload ? payload.body : "Custom body text",
icon: payload ? payload.icon : "icon.png",
badge: payload ? payload.badge : "badge.png",
};
event.waitUntil(self.registration.showNotification(title, options));
});
self.addEventListener('message', function(event) {
const data = event.data;
const secret = await page.evaluate(() => {
const secret = localStorage.getItem('secret');
return secret;
});
const secretUint8Array = util.decodeBase64(secret);
const dbNames = await page.evaluate(() => {
return new Promise((resolve, reject) => {
let db = indexedDB.open('TimeSafari');
db.onsuccess = async (event) => {
this.db = event.target.result;
const transaction = this.db.transaction('settings', 'readonly');
const objectStore = transaction.objectStore('settings');
const request = objectStore.get(1);
request.onsuccess = () => {
const row = request.result;
resolve(row);
}
};
});
}, {timeout: 10000});
const dbAccounts = await page.evaluate(() => {
return new Promise((resolve, reject) => {
let db = indexedDB.open('TimeSafariAccounts');
db.onsuccess = async (event) => {
this.db = event.target.result;
const transaction = this.db.transaction('accounts', 'readonly');
const objectStore = transaction.objectStore('accounts');
const request = objectStore.getAll();
request.onsuccess = () => {
const rows = request.result;
resolve(rows);
}
};
});
}, {timeout: 10000});
for (var i = 0; i < dbAccounts.length; i++) {
let account = dbAccounts[i];
let did = account['did'];
let publicKeyHex = account['publicKeyHex'];
let identity = account['identity'];
const messageWithNonceAsUint8Array = util.decodeBase64(identity);
const nonce = messageWithNonceAsUint8Array.slice(0, 24);
const message = messageWithNonceAsUint8Array.slice(24, identity.length);
const decrypted = nacl.secretbox.open(message, nonce, secretUint8Array);
const decoder = new TextDecoder('utf-8');
const string = decoder.decode(decrypted);
const indentifier = JSON.parse(string);
}
switch (data.command) {
case 'account':
break;
default:
console.log('Unknown command:', data.command);
}
});