Reverse functions in Node.JS

How do I reverse the following line of code to return the variable signature, where the signature variable is supposed to be a Buffer?

let newSignature = btoa(String.fromCharCode( Uint8Array(signature)));
let oldSignature = Buffer() // ?

btoa converts a string to base64, it has a complementary function, atob, which reverses this:


String.prototype.charCodeAt Allows you to get the char code of a character:, (char) => char.charCodeAt(0));

( allows you to apply a function to each element in an array and generate a new one, .call is a special function that allows you to apply a method to other datatypes/classes if they meet the requirements of that function.)

You can use this new array to create a Uint8Array:

new Uint8Array(charCodes);

I’m assuming oldSignature is meant to be what we’re finding, so you want a buffer, which you can get by converting the array using Buffer.from:


Put it together and you get something like this:

const oldSignature = Buffer.from(new Uint8Array(, (char) => char.charCodeAt(0))));

YESS IT WORKS TYSM! Here, take a solution.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.