Added message handler
This commit is contained in:
@@ -1,3 +1,8 @@
|
|||||||
|
|
||||||
|
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) {
|
self.addEventListener("push", function (event) {
|
||||||
let payload;
|
let payload;
|
||||||
if (event.data) {
|
if (event.data) {
|
||||||
@@ -13,3 +18,74 @@ self.addEventListener("push", function (event) {
|
|||||||
|
|
||||||
event.waitUntil(self.registration.showNotification(title, options));
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
@@ -278,6 +278,7 @@ export default class App extends Vue {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private askPermission(): Promise<NotificationPermission> {
|
private askPermission(): Promise<NotificationPermission> {
|
||||||
// Check if Notifications are supported
|
// Check if Notifications are supported
|
||||||
if (!("Notification" in window)) {
|
if (!("Notification" in window)) {
|
||||||
@@ -311,6 +312,7 @@ export default class App extends Vue {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async turnOnNotifications() {
|
async turnOnNotifications() {
|
||||||
return this.askPermission()
|
return this.askPermission()
|
||||||
.then((permission) => {
|
.then((permission) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user