Skip to content

Commit

Permalink
refactor!: fix encoding issue (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
gao-sun authored May 21, 2024
1 parent 1388cbd commit 08abea3
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 575 deletions.
3 changes: 0 additions & 3 deletions packages/rn-sample/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// eslint-disable-next-line import/no-unassigned-import
import '@logto/rn/polyfill';

import { LogtoProvider, Prompt, useLogto, type IdTokenClaims } from '@logto/rn';
import { StatusBar } from 'expo-status-bar';
import { useEffect, useState } from 'react';
Expand Down
8 changes: 4 additions & 4 deletions packages/rn-sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@
"ios": "expo run:ios"
},
"dependencies": {
"@expo/metro-runtime": "~3.1.3",
"@expo/metro-runtime": "~3.2.1",
"@logto/rn": "workspace:^",
"@react-native-async-storage/async-storage": "^1.22.0",
"@react-native-async-storage/async-storage": "^1.23.1",
"expo": "~51.0.8",
"expo-crypto": "^13.0.2",
"expo-secure-store": "^13.0.1",
"expo-status-bar": "~1.12.1",
"expo-web-browser": "^13.0.3",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "0.73.7",
"react-native": "0.74.1",
"react-native-web": "~0.19.6"
},
"devDependencies": {
"@babel/core": "^7.24.4",
"@silverhand/eslint-config": "^6.0.1",
"@silverhand/eslint-config-react": "^6.0.2",
"@types/react": "~18.2.45",
"@types/react": "~18.2.79",
"eslint": "^8.57.0",
"prettier": "^3.2.5",
"stylelint": "^15.0.0",
Expand Down
8 changes: 2 additions & 6 deletions packages/rn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
"import": "./lib/index.js",
"require": "./lib/index.js",
"types": "./lib/index.d.ts"
},
"./polyfill": {
"import": "./lib/polyfill.js",
"require": "./lib/polyfill.js"
}
},
"files": [
Expand Down Expand Up @@ -56,13 +52,13 @@
"@logto/client": "2.4.0",
"@logto/js": "4.0.0",
"crypto-es": "^2.1.0",
"js-base64": "^3.7.6"
"js-base64": "^3.7.7"
},
"peerDependencies": {
"@react-native-async-storage/async-storage": "^1.23.1",
"expo-crypto": "^13.0.2",
"expo-secure-store": "^13.0.1",
"expo-web-browser": "^13.0.3",
"react-native": ">=0.73.4 <1"
"react-native": ">=0.74.1 <1"
}
}
13 changes: 0 additions & 13 deletions packages/rn/src/polyfill.ts

This file was deleted.

5 changes: 3 additions & 2 deletions packages/rn/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import * as Crypto from 'expo-crypto';
import { encode, fromUint8Array, toUint8Array } from 'js-base64';
import { fromUint8Array } from 'js-base64';

export const generateRandomString = async (byteLength = 64) =>
fromUint8Array(await Crypto.getRandomBytesAsync(byteLength), true);

export const generateCodeChallenge = async (codeVerifier: string): Promise<string> => {
const encodedCodeVerifier = new TextEncoder().encode(codeVerifier);
const codeChallenge = new Uint8Array(
await Crypto.digest(Crypto.CryptoDigestAlgorithm.SHA256, toUint8Array(encode(codeVerifier)))
await Crypto.digest(Crypto.CryptoDigestAlgorithm.SHA256, encodedCodeVerifier)
);
return fromUint8Array(codeChallenge, true);
};
Loading

0 comments on commit 08abea3

Please sign in to comment.