|
|
@ -50,7 +50,7 @@ export class NotificationService { |
|
|
|
const vapidKeys: VapidKeys[] = await this.vapidService.getVapidKeys(); |
|
|
|
const vapidkey: VapidKeys = vapidKeys[0]; |
|
|
|
|
|
|
|
const encrypted = await this.encrypt(vapidkey, subscription.keys.p256dh, subscription.keys.auth, payloadBuffer); |
|
|
|
const encrypted = await this.encrypt(subscription.keys.p256dh, subscription.keys.auth, payloadBuffer); |
|
|
|
const endpoint = subscription.endpoint; |
|
|
|
|
|
|
|
const vapidHeaders = await this.vapidService.createVapidAuthHeader(endpoint, 12 * 60 * 60, 'mailto:example@example.com', vapidkey); |
|
|
@ -94,16 +94,15 @@ export class NotificationService { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private async encrypt(appKeys: VapidKeys, p256dh: string, auth: string, payload: Buffer): Promise<Buffer> { |
|
|
|
private async encrypt( p256dh: string, auth: string, payload: Buffer): Promise<Buffer> { |
|
|
|
try { |
|
|
|
const vapidPrivateKeyBase64: string = appKeys['privateKey']; |
|
|
|
const vapidPrivateKeyBuffer: Buffer = Buffer.from(vapidPrivateKeyBase64, 'base64'); |
|
|
|
const ecdh = crypto.createECDH('prime256v1'); |
|
|
|
ecdh.setPrivateKey(vapidPrivateKeyBuffer); |
|
|
|
ecdh.generateKeys(); |
|
|
|
const publicKeyBuffer: Buffer = Buffer.from(p256dh, 'base64'); |
|
|
|
|
|
|
|
return http_ece.encrypt(payload, { |
|
|
|
'privateKey': ecdh, |
|
|
|
'version': 'aes128gcm', |
|
|
|
'privateKey': ecdh, |
|
|
|
'dh': publicKeyBuffer, |
|
|
|
'authSecret': Buffer.from(auth) |
|
|
|
}); |
|
|
|