feat/push-notifications #34

Merged
retoor merged 16 commits from BordedDev/snek:feat/push-notifications into main 2025-06-06 11:25:09 +02:00
Contributor

This is the current push notifications code. It uses the full payload rather than the signal type. It creates needed certs and doesn't require any third-party libs outside the cryptography library

This is the current push notifications code. It uses the full payload rather than the signal type. It creates needed certs and doesn't require any third-party libs outside the cryptography library
BordedDev reviewed 2025-04-21 19:49:15 +02:00
@ -65,0 +51,4 @@
console.log("Notification closed", event);
})
self.addEventListener("fetch", (event) => {
Author
Contributor

Only added because somewhere while reading this was a requirement on some browsers to get push notifications to work with WPAs

Only added because somewhere while reading this was a requirement on some browsers to get push notifications to work with WPAs
BordedDev reviewed 2025-04-21 19:51:46 +02:00
@ -0,0 +20,4 @@
PRIVATE_KEY_FILE = Path("./notification-private.pem")
PRIVATE_KEY_PKCS8_FILE = Path("./notification-private.pkcs8.pem")
PUBLIC_KEY_FILE = Path("./notification-public.pem")
Author
Contributor

These keys need to be persisted because the public key is sent to the browser's PushNotification service.

The reason for the PKCS8 file is just for debugging and can be removed

These keys need to be persisted because the public key is sent to the browser's PushNotification service. The reason for the PKCS8 file is just for debugging and can be removed
BordedDev reviewed 2025-04-21 20:12:36 +02:00
@ -31,0 +8,4 @@
const keyResponse = await fetch('/push.json')
const keyData = await keyResponse.json()
const publicKey = Uint8Array.from(atob(keyData.publicKey), c => c.charCodeAt(0))
Author
Contributor

In the future this can be replaced with Uint8Array.fromBase64() It's just not available in chrome/old firefox ;P

In the future this can be replaced with `Uint8Array.fromBase64()` It's just not available in chrome/old firefox ;P
Owner

Then it's easy, i prefer this. Because let's face it, that frombase64 code doesn't do so much. Don't see a reason to exclude browsers for such simple functionality.

Then it's easy, i prefer this. Because let's face it, that frombase64 code doesn't do so much. Don't see a reason to exclude browsers for such simple functionality.
BordedDev reviewed 2025-04-21 20:15:42 +02:00
@ -0,0 +149,4 @@
salt = os.urandom(16)
user_key_bytes = base64.urlsafe_b64decode(p256dh + "==")
Author
Contributor

Python base64 parsing discards excessive padding (=) but will not add it if it's missing, causing it to think the base64 is bad if it isn't 4 char aligned

Python base64 parsing discards excessive padding (`=`) but will not add it if it's missing, causing it to think the base64 is bad if it isn't 4 char aligned
BordedDev reviewed 2025-04-21 20:17:24 +02:00
@ -31,0 +52,4 @@
}
});
};
registerServiceWorker(true).catch(console.error);
Author
Contributor

Some browsers will show the permission prompt immediately, others require a "registered" interaction

Some browsers will show the permission prompt immediately, others require a "registered" interaction
BordedDev force-pushed feat/push-notifications from 5a5d1cb3dd to 272998f757 2025-05-31 16:36:39 +02:00 Compare
BordedDev added 1 commit 2025-05-31 19:09:05 +02:00
BordedDev added 1 commit 2025-05-31 23:10:01 +02:00
BordedDev added 1 commit 2025-05-31 23:29:51 +02:00
BordedDev added 1 commit 2025-06-01 00:54:18 +02:00
BordedDev added 1 commit 2025-06-01 00:56:45 +02:00
BordedDev added 2 commits 2025-06-01 13:04:02 +02:00
BordedDev added 1 commit 2025-06-05 22:06:56 +02:00
BordedDev added 1 commit 2025-06-06 11:24:46 +02:00
retoor merged commit 831b5c17cd into main 2025-06-06 11:25:09 +02:00
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: retoor/snek#34
No description provided.