Skip to content

Commit

Permalink
Ensure EthJS and Grandine talk (#3511)
Browse files Browse the repository at this point in the history
* jwt-simple: ensure unpadded payloads are accepted

* jwt-simple: ensure encoded jwts are also unpadded
  • Loading branch information
jochem-brouwer authored and holgerd77 committed Aug 15, 2024
1 parent fcd4854 commit 5ce4668
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/client/src/ext/jwt-simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
Expand Down Expand Up @@ -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())) {
Expand Down Expand Up @@ -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('.')
Expand Down

0 comments on commit 5ce4668

Please sign in to comment.