use native base64url encoding instead of module
[squeep-indieauth-helper] / lib / communication.js
index a9eb66100d2c2ef9525b4dc75bddb31b0769c060..82400c354e2864d5124b605fcaf965169188ecf8 100644 (file)
@@ -2,7 +2,6 @@
 
 const axios = require('axios');
 const { mf2 } = require('microformats-parser');
-const { base64ToBase64URL } = require('@squeep/base64url');
 const { parse: parseLinkHeader } = require('@squeep/web-linking');
 const { Iconv } = require('iconv');
 const { version: packageVersion, name: packageName } = require('../package.json');
@@ -61,7 +60,7 @@ class Communication {
   static _challengeFromVerifier(verifier) {
     const hash = createHash('sha256');
     hash.update(verifier);
-    return base64ToBase64URL(hash.digest('base64'));
+    return hash.digest('base64url');
   }
 
 
@@ -73,7 +72,7 @@ class Communication {
    */
   /**
    * Create a code verifier and its challenge.
-   * @param {Number} length
+   * @param {Number} length of verifier string, between 43 and 128
    * @returns {Promise<PKCEData>}
    */
   static async generatePKCE(length = 128) {
@@ -83,7 +82,7 @@ class Communication {
 
     const bufferLength = Math.floor(length * 3 / 4);
     const randomBuffer = await randomBytesAsync(bufferLength);
-    const verifier = base64ToBase64URL(randomBuffer.toString('base64'));
+    const verifier = randomBuffer.toString('base64url');
   
     const challenge = Communication._challengeFromVerifier(verifier);
 
@@ -219,9 +218,10 @@ class Communication {
 
 
   /**
-   * Parse and add any header link relations to mf data.
+   * Parse and add any header link relations from response to microformat data.
    * @param {Object} microformat
    * @param {Object} response
+   * @param {Object} response.headers
    */
   _mergeLinkHeader(microformat, response) {
     const _scope = _fileScope('_mergeLinkHeader');