Skip to content

Commit 1626e28

Browse files
committed
refactor: use native btoa supported on RN 0.74+
1 parent 0ecfa91 commit 1626e28

File tree

3 files changed

+2
-12
lines changed

3 files changed

+2
-12
lines changed

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
},
6565
"homepage": "https://github.com/dcangulo/react-native-pkce-challenge#readme",
6666
"dependencies": {
67-
"base-64": "^1.0.0",
6867
"js-sha256": "^0.11.0"
6968
},
7069
"devDependencies": {

src/utils.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { sha256 } from 'js-sha256';
2-
import base64 from 'base-64';
32

43
const BYTE_LENGTH = 96;
54

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

1514
export function generateChallenge(verifier: string) {
1615
const digest = sha256.digest(verifier);
17-
const hash = base64.encode(String.fromCharCode(...new Uint8Array(digest)));
16+
const hash = btoa(String.fromCharCode(...new Uint8Array(digest)));
1817

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

3130
const buffer = new Uint8Array(byteLength).map(() => Math.floor(Math.random() * 256));
32-
const bytes = base64.encode(String.fromCharCode(...new Uint8Array(buffer)));
31+
const bytes = btoa(String.fromCharCode(...new Uint8Array(buffer)));
3332

3433
return bytes;
3534
}

yarn.lock

-8
Original file line numberDiff line numberDiff line change
@@ -4099,13 +4099,6 @@ __metadata:
40994099
languageName: node
41004100
linkType: hard
41014101

4102-
"base-64@npm:^1.0.0":
4103-
version: 1.0.0
4104-
resolution: "base-64@npm:1.0.0"
4105-
checksum: d10b64a1fc9b2c5a5f39f1ce1e6c9d1c5b249222bbfa3a0604c592d90623caf74419983feadd8a170f27dc0c3389704f72faafa3e645aeb56bfc030c93ff074a
4106-
languageName: node
4107-
linkType: hard
4108-
41094102
"base64-js@npm:^1.3.1, base64-js@npm:^1.5.1":
41104103
version: 1.5.1
41114104
resolution: "base64-js@npm:1.5.1"
@@ -9730,7 +9723,6 @@ __metadata:
97309723
"@react-native/eslint-config": ^0.73.1
97319724
"@types/base-64": ^1.0.2
97329725
"@types/react": ^18.2.44
9733-
base-64: ^1.0.0
97349726
commitlint: ^17.0.2
97359727
del-cli: ^5.1.0
97369728
eslint: ^8.51.0

0 commit comments

Comments
 (0)