From 5ce46680aa5eaf6c902acb8f6a1af666a0adfac7 Mon Sep 17 00:00:00 2001 From: Jochem Brouwer Date: Wed, 17 Jul 2024 13:16:25 +0200 Subject: [PATCH] Ensure EthJS and Grandine talk (#3511) * jwt-simple: ensure unpadded payloads are accepted * jwt-simple: ensure encoded jwts are also unpadded --- packages/client/src/ext/jwt-simple.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/client/src/ext/jwt-simple.ts b/packages/client/src/ext/jwt-simple.ts index 9357ef52c3..45ce840259 100644 --- a/packages/client/src/ext/jwt-simple.ts +++ b/packages/client/src/ext/jwt-simple.ts @@ -7,7 +7,7 @@ * module dependencies */ import { bytesToUtf8, utf8ToBytes } from '@ethereumjs/util' -import { base64url } from '@scure/base' +import { base64url, base64urlnopad } from '@scure/base' import crypto from 'crypto' /** @@ -121,7 +121,7 @@ const decode = function jwt_decode( // base64 decode and parse JSON const header = JSON.parse(bytesToUtf8(base64url.decode(headerSeg))) - const payload = JSON.parse(bytesToUtf8(base64url.decode(payloadSeg))) + const payload = JSON.parse(bytesToUtf8(base64urlnopad.decode(payloadSeg))) if (!noVerify) { if (!algorithm && /BEGIN( RSA)? PUBLIC KEY/.test(key.toString())) { @@ -193,7 +193,7 @@ const encode = function jwt_encode( // create segments, all segments should be base64 string const segments = [] segments.push(base64url.encode(utf8ToBytes(JSON.stringify(header)))) - segments.push(base64url.encode(utf8ToBytes(JSON.stringify(payload)))) + segments.push(base64urlnopad.encode(utf8ToBytes(JSON.stringify(payload)))) segments.push(sign(segments.join('.'), key, signingMethod, signingType)) return segments.join('.')