11'use strict' ;
22
33const crypto = require ( 'crypto' ) ;
4- const urlBase64 = require ( 'urlsafe-base64' ) ;
54const asn1 = require ( 'asn1.js' ) ;
65const jws = require ( 'jws' ) ;
76const { URL } = require ( 'url' ) ;
87
98const WebPushConstants = require ( './web-push-constants.js' ) ;
9+ const urlBase64Helper = require ( './urlsafe-base64-helper' ) ;
1010
1111/**
1212 * DEFAULT_EXPIRATION is set to seconds in 12 hours
@@ -60,8 +60,8 @@ function generateVAPIDKeys() {
6060 }
6161
6262 return {
63- publicKey : urlBase64 . encode ( publicKeyBuffer ) ,
64- privateKey : urlBase64 . encode ( privateKeyBuffer )
63+ publicKey : urlBase64Helper . encode ( publicKeyBuffer ) ,
64+ privateKey : urlBase64Helper . encode ( privateKeyBuffer )
6565 } ;
6666}
6767
@@ -100,11 +100,11 @@ function validatePublicKey(publicKey) {
100100 + 'encoded string.' ) ;
101101 }
102102
103- if ( ! urlBase64 . validate ( publicKey ) ) {
103+ if ( ! urlBase64Helper . validate ( publicKey ) ) {
104104 throw new Error ( 'Vapid public key must be a URL safe Base 64 (without "=")' ) ;
105105 }
106106
107- publicKey = urlBase64 . decode ( publicKey ) ;
107+ publicKey = urlBase64Helper . decode ( publicKey ) ;
108108
109109 if ( publicKey . length !== 65 ) {
110110 throw new Error ( 'Vapid public key should be 65 bytes long when decoded.' ) ;
@@ -121,11 +121,11 @@ function validatePrivateKey(privateKey) {
121121 + 'encoded string.' ) ;
122122 }
123123
124- if ( ! urlBase64 . validate ( privateKey ) ) {
124+ if ( ! urlBase64Helper . validate ( privateKey ) ) {
125125 throw new Error ( 'Vapid private key must be a URL safe Base 64 (without "=")' ) ;
126126 }
127127
128- privateKey = urlBase64 . decode ( privateKey ) ;
128+ privateKey = urlBase64Helper . decode ( privateKey ) ;
129129
130130 if ( privateKey . length !== 32 ) {
131131 throw new Error ( 'Vapid private key should be 32 bytes long when decoded.' ) ;
@@ -203,7 +203,7 @@ function getVapidHeaders(audience, subject, publicKey, privateKey, contentEncodi
203203 validatePublicKey ( publicKey ) ;
204204 validatePrivateKey ( privateKey ) ;
205205
206- privateKey = urlBase64 . decode ( privateKey ) ;
206+ privateKey = urlBase64Helper . decode ( privateKey ) ;
207207
208208 if ( expiration ) {
209209 validateExpiration ( expiration ) ;
0 commit comments