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