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 Jul 17, 2024
1 parent 03fa912 commit 41931d6
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 41931d6

Please sign in to comment.