auth0 / node-jwa

JSON Web Algorithms
http://tools.ietf.org/id/draft-ietf-jose-json-web-algorithms-08.html
MIT License
98 stars 42 forks source link

Enhancement/ tech debt: use Node's built-in toString(base64url) #48

Open webketje opened 12 months ago

webketje commented 12 months ago

Describe the problem you'd like to have solved

Currently the code has 2 functions fromBase64 and toBase64 with custom string replacement. Starting from (at least) Node.js 14.x base64url is a valid parameter to the Buffer.toString API. (I traced this by looking at the Node.js API docs per version and noting when the base64url was included as valid parameter).

Describe the ideal solution

The code of these functions can be rewritten to:

function toBase64(base64url) {
  return Buffer.from(base64url.toString(), 'base64url').toString('base64')
}
function fromBase64(base64) {
  return Buffer.from(base64.toString(), 'base64').toString('base64url')
}

...taking advantage of the built-in Buffer API

Additionally, might want to specify { "engines": { "node": ">=14.x" }} in package.json