https://github.com/screendriver/convert-vapid-public-key
🔑 Convert a VAPID public key to an Uint8Array
https://github.com/screendriver/convert-vapid-public-key
push-notifications vapid web-push
Last synced: about 1 month ago
JSON representation
🔑 Convert a VAPID public key to an Uint8Array
- Host: GitHub
- URL: https://github.com/screendriver/convert-vapid-public-key
- Owner: screendriver
- License: mit
- Created: 2018-11-14T19:07:15.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2025-03-10T17:57:54.000Z (about 2 months ago)
- Last Synced: 2025-03-15T00:51:54.338Z (about 2 months ago)
- Topics: push-notifications, vapid, web-push
- Language: TypeScript
- Homepage:
- Size: 4.98 MB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# convert-vapid-public-key
[](https://github.com/screendriver/convert-vapid-public-key/actions)
To subscribe to [Web Push Notifications](https://developers.google.com/web/fundamentals/push-notifications/) you have to provide an Base64 application server key that needs to be converted to an [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array). This package helps you with the conversion from a Base64 string to an `Uint8Array`.
## Installation 🏗
```sh
$ npm install --save convert-vapid-public-key
```or if you use [Yarn](https://yarnpkg.com) 🐈
```sh
$ yarn add convert-vapid-public-key
```## Usage 🔨
```ts
import convertVapidKey from "convert-vapid-public-key";async function subscribe() {
const registration = await navigator.serviceWorker.register("service-worker.js");
const subscribeOptions = {
userVisibleOnly: true,
applicationServerKey: convertVapidKey(""),
};
const pushSubscription = await registration.pushManager.subscribe(subscribeOptions);
// ...
}
```