-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
108 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ let vapidPublicKey: string | |
let vapidPrivateKey: Object | ||
|
||
// TODO: Load from configuration | ||
const vapid = { VAPID_EMAIL: '[email protected]' } | ||
const vapid = { VAPID_EMAIL: 'mailto:[email protected]' } | ||
|
||
export const initVapid = async () => { | ||
const vapidKeyPair = await sbp('chelonia/db/get', '_private_immutable_vapid_key').then(async (vapidKeyPair: string): Promise<[Object, string]> => { | ||
|
@@ -53,15 +53,7 @@ export const initVapid = async () => { | |
} | ||
|
||
const generateJwt = async (endpoint: URL): Promise<string> => { | ||
const privateKey = await crypto.subtle.importKey( | ||
'jwk', | ||
vapidPrivateKey, | ||
{ name: 'ECDSA', namedCurve: 'P-256' }, | ||
false, | ||
['sign'] | ||
) | ||
|
||
const now = Math.round(Date.now() / 1e3) | ||
const now = Date.now() / 1e3 | 0 | ||
|
||
const audience = endpoint.origin | ||
|
||
|
@@ -72,9 +64,9 @@ const generateJwt = async (endpoint: URL): Promise<string> => { | |
const body = Buffer.from(JSON.stringify( | ||
Object.fromEntries([ | ||
['aud', audience], | ||
['exp', now + 60], | ||
['exp', now + 90], | ||
['iat', now], | ||
['nbf', now - 60], | ||
['nbf', now - 90], | ||
['sub', vapid.VAPID_EMAIL] | ||
]) | ||
// $FlowFixMe[incompatible-call] | ||
|
@@ -83,11 +75,13 @@ const generateJwt = async (endpoint: URL): Promise<string> => { | |
const signature = Buffer.from( | ||
await crypto.subtle.sign( | ||
{ name: 'ECDSA', hash: 'SHA-256' }, | ||
privateKey, | ||
vapidPrivateKey, | ||
Buffer.from([header, body].join('.')) | ||
) | ||
).toString('base64url') | ||
|
||
console.error('@@@JWT', [header, body, signature].join('.')) | ||
|
||
return [header, body, signature].join('.') | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.