Skip to content

Commit 9bae3fe

Browse files
authored
Merge pull request #190 from mbret/develop
release
2 parents 0d8cfcd + d03f607 commit 9bae3fe

File tree

14 files changed

+1942
-1325
lines changed

14 files changed

+1942
-1325
lines changed

Diff for: package-lock.json

+1,899-1,288
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
},
2828
"devDependencies": {
2929
"@rollup/plugin-replace": "^6.0.1",
30-
"@types/crypto-js": "^4.1.1",
3130
"@types/node": "^20",
3231
"@types/react": "^18.0.28",
3332
"@types/react-dom": "^18.0.11",

Diff for: packages/api/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"abort-controller": "^3.0.0",
3232
"axios": "^1.3.4",
3333
"cheerio": "^1.0.0-rc.10",
34-
"crypto-js": "^4.2.0",
3534
"dropbox": "^10.34.0",
3635
"fast-xml-parser": "^4.5.0",
3736
"firebase": "^11.0.1",

Diff for: packages/api/src/libs/couch/dbHelpers.ts

-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,6 @@ export const getNanoDbForUser = async (name: string, privateKey: string) => {
362362
export const getNano = async ({ jwtToken }: { jwtToken?: string } = {}) => {
363363
return createNano({
364364
url: COUCH_DB_URL,
365-
// log: (...args) => console.log('nano', JSON.stringify(...args)),
366365
requestDefaults: {
367366
headers: {
368367
"content-type": "application/json",

Diff for: packages/api/src/libs/middy/withMiddy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Sentry.init({
1818
// We recommend adjusting this value in production
1919
tracesSampleRate: 1.0,
2020
// Set sampling rate for profiling - this is relative to tracesSampleRate
21-
profilesSampleRate: 1.0,
21+
profilesSampleRate: 1.0
2222
})
2323

2424
export const withMiddy = (

Diff for: packages/shared/package.json

-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,5 @@
1616
"start": "vite build --watch --mode development",
1717
"build": "tsc",
1818
"test": "vitest run"
19-
},
20-
"peerDependencies": {
21-
"crypto-js": "4.x"
2219
}
2320
}

Diff for: packages/shared/src/crypto.ts

-10
This file was deleted.

Diff for: packages/shared/src/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ export * from "./db/books"
7575
export * from "./dataSources"
7676
export * from "./sorting"
7777

78-
export * as crypto from "./crypto"
79-
8078
export { ObokuErrorCode, ObokuSharedError } from "./errors"
8179

8280
export * from "./plugin-imhentai-shared"

Diff for: packages/shared/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020
"noUncheckedIndexedAccess": true,
2121
"useUnknownInCatchVariables": true
2222
},
23-
"include": ["src"]
23+
"include": ["src", "../web/src/common/crypto.ts"]
2424
}

Diff for: packages/web/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"@tanstack/react-virtual": "^3.8.4",
2121
"gesturx": "^1.8.2",
2222
"buffer": "^6.0.3",
23-
"crypto-js": "^4.2.0",
2423
"date-fns": "^4.1.0",
2524
"dropbox": "^10.34.0",
2625
"firebase": "^11.0.1",

Diff for: packages/web/src/auth/UnlockContentsDialog.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import {
77
DialogTitle,
88
TextField
99
} from "@mui/material"
10-
import { crypto } from "@oboku/shared"
1110
import { useEffect } from "react"
1211
import { Controller, SubmitHandler, useForm } from "react-hook-form"
1312
import { errorToHelperText } from "../common/forms/errorToHelperText"
1413
import { PreventAutocompleteFields } from "../common/forms/PreventAutocompleteFields"
1514
import { useModalNavigationControl } from "../navigation/useModalNavigationControl"
1615
import { libraryStateSignal } from "../library/books/states"
1716
import { useSettings } from "../settings/helpers"
17+
import { hashContentPassword } from "../common/crypto"
1818

1919
type Inputs = {
2020
unlockPassword: string
@@ -44,7 +44,7 @@ export const UnlockContentsDialog = ({
4444
)
4545

4646
const onSubmit: SubmitHandler<Inputs> = async (data) => {
47-
const hashedPassword = crypto.hashContentPassword(data.unlockPassword)
47+
const hashedPassword = await hashContentPassword(data.unlockPassword)
4848

4949
if (contentPassword === hashedPassword) {
5050
libraryStateSignal.setValue((state) => ({

Diff for: packages/web/src/auth/useSignIn.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@ import { CancelError } from "../errors/errors.shared"
1313

1414
const provider = new GoogleAuthProvider()
1515

16-
const auth = getAuth()
17-
1816
export const useSignIn = () => {
1917
const { mutateAsync: reCreateDb } = useReCreateDb()
2018

2119
const signIn = useCallback(() => {
2220
lock("authentication")
2321

22+
/**
23+
* @important
24+
* This should be at the root of module but there is a bug where events
25+
* get added forever.
26+
* @see https://github.com/firebase/firebase-js-sdk/issues/8642
27+
*/
28+
const auth = getAuth()
29+
2430
return from(signInWithPopup(auth, provider)).pipe(
2531
catchError((e) => {
2632
if (e.code === "auth/popup-closed-by-user") throw new CancelError()

Diff for: packages/web/src/common/crypto.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* The contentPassword is for user content protection. It is made to work
3+
* offline and therefore is not secured yet. This is not intended for
4+
* fully secured solution
5+
*/
6+
export const hashContentPassword = async (password: string) => {
7+
const encoder = new TextEncoder()
8+
const data = encoder.encode(password)
9+
10+
const buffer = await window.crypto.subtle.digest(`SHA-256`, data)
11+
12+
// Convert ArrayBuffer to hex string
13+
const hashArray = Array.from(new Uint8Array(buffer))
14+
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("")
15+
16+
return hashHex
17+
}

Diff for: packages/web/src/settings/helpers.ts

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { crypto } from "@oboku/shared"
21
import { Database } from "../rxdb"
32
import { useForeverQuery, useMutation } from "reactjrx"
43
import { getLatestDatabase, latestDatabase$ } from "../rxdb/RxDbProvider"
5-
import { from, map, mergeMap, of, switchMap } from "rxjs"
4+
import { from, map, mergeMap, switchMap } from "rxjs"
65
import { SettingsDocType } from "../rxdb/collections/settings"
76
import { getSettingsDocument } from "./dbHelpers"
7+
import { hashContentPassword } from "../common/crypto"
88

99
const getSettingsOrThrow = (database: Database) => {
1010
return getSettingsDocument(database).pipe(
@@ -21,8 +21,8 @@ const getSettingsOrThrow = (database: Database) => {
2121
export const useUpdateContentPassword = () => {
2222
const { mutate: updateSettings } = useUpdateSettings()
2323

24-
return (password: string) => {
25-
const hashed = crypto.hashContentPassword(password)
24+
return async (password: string) => {
25+
const hashed = await hashContentPassword(password)
2626

2727
updateSettings({
2828
contentPassword: hashed
@@ -42,15 +42,17 @@ export const useValidateAppPassword = (options: {
4242

4343
return getLatestDatabase().pipe(
4444
mergeMap((database) => getSettingsOrThrow(database)),
45-
mergeMap((settings) => {
46-
const hashedInput = crypto.hashContentPassword(input)
47-
48-
if (hashedInput !== settings.contentPassword) {
49-
throw new Error("Invalid password")
50-
}
45+
mergeMap((settings) =>
46+
from(hashContentPassword(input)).pipe(
47+
map((hashedInput) => {
48+
if (hashedInput !== settings.contentPassword) {
49+
throw new Error("Invalid password")
50+
}
5151

52-
return of(null)
53-
})
52+
return null
53+
})
54+
)
55+
)
5456
)
5557
}
5658
})

0 commit comments

Comments
 (0)