Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const decode = (token, payloadOnly = true) => {
const [headerB64, bodyB64, sigB64] = token.split('.');
const header = JSON.parse(fromBase64(headerB64));
const body = JSON.parse(fromBase64(bodyB64));
const sig = Buffer.from(fromBase64(sigB64)).toString('hex');
if (payloadOnly) {
return body;
}
return { header, body, signature: `0x${toStrictHex(sig)}` };
};