Skip to content

Commit

Permalink
Merge pull request #514 from dcangulo/btoa
Browse files Browse the repository at this point in the history
refactor: use native btoa supported on RN 0.74+
  • Loading branch information
dcangulo authored Dec 15, 2024
2 parents 10b876b + 1626e28 commit 8fed961
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 12 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
},
"homepage": "https://github.com/dcangulo/react-native-pkce-challenge#readme",
"dependencies": {
"base-64": "^1.0.0",
"js-sha256": "^0.11.0"
},
"devDependencies": {
Expand Down
5 changes: 2 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { sha256 } from 'js-sha256';
import base64 from 'base-64';

const BYTE_LENGTH = 96;

Expand All @@ -14,7 +13,7 @@ export function base64UrlEncode(str: string) {

export function generateChallenge(verifier: string) {
const digest = sha256.digest(verifier);
const hash = base64.encode(String.fromCharCode(...new Uint8Array(digest)));
const hash = btoa(String.fromCharCode(...new Uint8Array(digest)));

return base64UrlEncode(hash);
}
Expand All @@ -29,7 +28,7 @@ export function getRandomBase64StringFallback(byteLength: number) {
console.warn('Native getRandomValues function not found. Falling back to insecure Math.random.');

const buffer = new Uint8Array(byteLength).map(() => Math.floor(Math.random() * 256));
const bytes = base64.encode(String.fromCharCode(...new Uint8Array(buffer)));
const bytes = btoa(String.fromCharCode(...new Uint8Array(buffer)));

return bytes;
}
Expand Down
8 changes: 0 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4099,13 +4099,6 @@ __metadata:
languageName: node
linkType: hard

"base-64@npm:^1.0.0":
version: 1.0.0
resolution: "base-64@npm:1.0.0"
checksum: d10b64a1fc9b2c5a5f39f1ce1e6c9d1c5b249222bbfa3a0604c592d90623caf74419983feadd8a170f27dc0c3389704f72faafa3e645aeb56bfc030c93ff074a
languageName: node
linkType: hard

"base64-js@npm:^1.3.1, base64-js@npm:^1.5.1":
version: 1.5.1
resolution: "base64-js@npm:1.5.1"
Expand Down Expand Up @@ -9730,7 +9723,6 @@ __metadata:
"@react-native/eslint-config": ^0.73.1
"@types/base-64": ^1.0.2
"@types/react": ^18.2.44
base-64: ^1.0.0
commitlint: ^17.0.2
del-cli: ^5.1.0
eslint: ^8.51.0
Expand Down

0 comments on commit 8fed961

Please sign in to comment.