Skip to content

Commit c459c87

Browse files
committed
Ensure argument is Uint8Array in uint8arrayToBase64url example
1 parent 976b095 commit c459c87

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

README

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,11 @@ function base64urlToUint8array(base64Bytes) {
202202
return base64js.toByteArray((base64Bytes + padding).replace(/\//g, "_").replace(/\+/g, "-"));
203203
}
204204
function uint8arrayToBase64url(bytes) {
205-
return base64js.fromByteArray(bytes).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
205+
if (bytes instanceof Uint8Array) {
206+
return base64js.fromByteArray(bytes).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
207+
} else {
208+
return uint8arrayToBase64url(new Uint8Array(bytes));
209+
}
206210
}
207211

208212
fetch(/* ... */) // Make the call that returns the credentialCreateJson above
@@ -314,7 +318,11 @@ function base64urlToUint8array(base64Bytes) {
314318
return base64js.toByteArray((base64Bytes + padding).replace(/\//g, "_").replace(/\+/g, "-"));
315319
}
316320
function uint8arrayToBase64url(bytes) {
317-
return base64js.fromByteArray(bytes).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
321+
if (bytes instanceof Uint8Array) {
322+
return base64js.fromByteArray(bytes).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
323+
} else {
324+
return uint8arrayToBase64url(new Uint8Array(bytes));
325+
}
318326
}
319327

320328
fetch(/* ... */) // Make the call that returns the credentialGetJson above

0 commit comments

Comments
 (0)