From 01e5f4f63e419ac0267e7615491ecc75adeabf1f Mon Sep 17 00:00:00 2001 From: Dave Longley Date: Wed, 2 Oct 2024 19:24:23 -0400 Subject: [PATCH] Ensure text encoding/decoding is performed. --- lib/DidJwkDriver.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/DidJwkDriver.js b/lib/DidJwkDriver.js index 6f44524..7cd7f23 100644 --- a/lib/DidJwkDriver.js +++ b/lib/DidJwkDriver.js @@ -172,7 +172,7 @@ export class DidJwkDriver { let jwkJson; let jwk; try { - jwkJson = base64url.decode(encodedJwk); + jwkJson = new TextDecoder().decode(base64url.decode(encodedJwk)); } catch(e) { const error = new Error( `Could not decode base64url-encoded JWK from "${encodedJwk}".`); @@ -220,7 +220,9 @@ export class DidJwkDriver { did, jwk, verificationMethodType = 'JsonWebKey' } = {}) { if(did === undefined) { - did = `did:jwk:${base64url.encode(JSON.stringify(jwk))}`; + const encoded = base64url.encode( + new TextEncoder().encode(JSON.stringify(jwk))); + did = `did:jwk:${encoded}`; } else if(typeof did !== 'string') { throw new TypeError('"did" must be a string.'); }