Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last minute v2 fixes #2007

Merged
merged 10 commits into from
Oct 10, 2024
Merged
54 changes: 0 additions & 54 deletions .github/workflows/tests.yml

This file was deleted.

33 changes: 33 additions & 0 deletions packages/core/src/encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export const encryptHistory = async (data: any): Promise<ArrayBuffer> => {
const iv = getIv()
const storedKey = await getKeyFromSessionStorage()
const key = await getOrCreateKey(storedKey)

if (!key) {
throw new Error('Unable to encrypt history')
}

const encrypted = await encryptData(iv, key, data)

return encrypted
Expand All @@ -34,6 +39,12 @@ const encryptData = async (iv: Uint8Array, key: CryptoKey, data: any) => {
throw new Error('Unable to encrypt history')
}

if (typeof window.crypto.subtle === 'undefined') {
console.warn('Encryption is not supported in this environment. SSL is required.')

return Promise.resolve(data)
}

const textEncoder = new TextEncoder()
const str = JSON.stringify(data)
const encoded = new Uint8Array(str.length)
Expand All @@ -51,6 +62,12 @@ const encryptData = async (iv: Uint8Array, key: CryptoKey, data: any) => {
}

const decryptData = async (iv: Uint8Array, key: CryptoKey, data: any) => {
if (typeof window.crypto.subtle === 'undefined') {
console.warn('Decryption is not supported in this environment. SSL is required.')

return Promise.resolve(data)
}

const decrypted = await window.crypto.subtle.decrypt(
{
name: 'AES-GCM',
Expand Down Expand Up @@ -78,6 +95,12 @@ const getIv = () => {
}

const createKey = async () => {
if (typeof window.crypto.subtle === 'undefined') {
console.warn('Encryption is not supported in this environment. SSL is required.')

return Promise.resolve(null)
}

return window.crypto.subtle.generateKey(
{
name: 'AES-GCM',
Expand All @@ -89,6 +112,12 @@ const createKey = async () => {
}

const saveKey = async (key: CryptoKey) => {
if (typeof window.crypto.subtle === 'undefined') {
console.warn('Encryption is not supported in this environment. SSL is required.')

return Promise.resolve()
}

const keyData = await window.crypto.subtle.exportKey('raw', key)

SessionStorage.set(historySessionStorageKeys.key, Array.from(new Uint8Array(keyData)))
Expand All @@ -101,6 +130,10 @@ const getOrCreateKey = async (key: CryptoKey | null) => {

const newKey = await createKey()

if (!newKey) {
return null
}

await saveKey(newKey)

return newKey
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/Deferred.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Deferred = ({ children, data, fallback }: DeferredProps) => {
const keys = Array.isArray(data) ? data : [data]

useEffect(() => {
setLoaded(loaded || keys.every((key) => pageProps[key] !== undefined))
setLoaded(keys.every((key) => pageProps[key] !== undefined))
}, [pageProps, keys])

return loaded ? children : fallback
Expand Down
13 changes: 8 additions & 5 deletions playgrounds/react/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^8.0.2",
"guzzlehttp/guzzle": "^7.2",
"inertiajs/inertia-laravel": "^1.2",
"laravel/framework": "^9.19",
"laravel/sanctum": "^3.0",
"inertiajs/inertia-laravel": "2.x-dev",
"laravel/framework": "^10.0",
"laravel/sanctum": "^3.2",
"laravel/tinker": "^2.7"
},
"require-dev": {
Expand All @@ -19,7 +22,7 @@
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^6.1",
"phpunit/phpunit": "^9.5.10",
"spatie/laravel-ignition": "^1.0"
"spatie/laravel-ignition": "^2.0"
},
"autoload": {
"psr-4": {
Expand Down
Loading
Loading