Skip to content

Instantly share code, notes, and snippets.

@kypflug

kypflug/sw-9.js Secret

Created December 15, 2017 01:59
Show Gist options
  • Save kypflug/8020af4245f5afe3ddd95cbe3527011e to your computer and use it in GitHub Desktop.
Save kypflug/8020af4245f5afe3ddd95cbe3527011e to your computer and use it in GitHub Desktop.
function urlBase64ToUint8Array(base64String) {
const padding = '='.repeat((4 - base64String.length % 4) % 4);
const base64 = (base64String + padding)
.replace(/\-/g, '+')
.replace(/_/g, '/');
const rawData = window.atob(base64);
const outputArray = new Uint8Array(rawData.length);
for (let i = 0; i < rawData.length; ++i) {
outputArray[i] = rawData.charCodeAt(i);
}
return outputArray;
}
fetch('./app_pubkey')
.then(function(res) {
res.json().then(function(data) {
var appPubkey = data.key;
registerPush(urlBase64ToUint8Array(appPubkey));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment