[fix] sodium not loading
This commit is contained in:
@@ -39,55 +39,67 @@ export const novelLogin = async () => {
|
|||||||
|
|
||||||
|
|
||||||
alertWait('Logging in to NovelAI')
|
alertWait('Logging in to NovelAI')
|
||||||
const _sodium = await import('libsodium-wrappers-sumo')
|
|
||||||
await sleep(1000)
|
|
||||||
await _sodium.ready
|
|
||||||
const sodium = _sodium;
|
|
||||||
|
|
||||||
// I don't know why, but this is needed to make it work
|
let tries = 0
|
||||||
console.log(sodium)
|
let error = ''
|
||||||
await sleep(1000)
|
while (tries < 3) {
|
||||||
|
try {
|
||||||
|
|
||||||
const key = sodium
|
const _sodium = await import('libsodium-wrappers-sumo')
|
||||||
.crypto_pwhash(
|
await sleep(1000)
|
||||||
64,
|
await _sodium.ready
|
||||||
new Uint8Array(Buffer.from(password)),
|
const sodium = _sodium;
|
||||||
sodium.crypto_generichash(
|
|
||||||
sodium.crypto_pwhash_SALTBYTES,
|
|
||||||
password.slice(0, 6) + username + 'novelai_data_access_key'
|
|
||||||
),
|
|
||||||
2,
|
|
||||||
2e6,
|
|
||||||
sodium.crypto_pwhash_ALG_ARGON2ID13,
|
|
||||||
'base64'
|
|
||||||
)
|
|
||||||
.slice(0, 64)
|
|
||||||
|
|
||||||
const r = await globalFetch('https://api.novelai.net/user/login', {
|
// I don't know why, but this is needed to make it work
|
||||||
method: 'POST',
|
console.log(sodium)
|
||||||
headers: {
|
await sleep(1000)
|
||||||
Accept: 'application/json',
|
|
||||||
'Content-Type': 'application/json',
|
const key = sodium
|
||||||
},
|
.crypto_pwhash(
|
||||||
body:{
|
64,
|
||||||
key: key
|
new Uint8Array(Buffer.from(password)),
|
||||||
|
sodium.crypto_generichash(
|
||||||
|
sodium.crypto_pwhash_SALTBYTES,
|
||||||
|
password.slice(0, 6) + username + 'novelai_data_access_key'
|
||||||
|
),
|
||||||
|
2,
|
||||||
|
2e6,
|
||||||
|
sodium.crypto_pwhash_ALG_ARGON2ID13,
|
||||||
|
'base64'
|
||||||
|
)
|
||||||
|
.slice(0, 64)
|
||||||
|
|
||||||
|
const r = await globalFetch('https://api.novelai.net/user/login', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body:{
|
||||||
|
key: key
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if ((!r.ok) || (!r.data?.accessToken)) {
|
||||||
|
alertError(`Failed to authenticate with NovelAI: ${r.data?.message ?? r.data}`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = r.data?.accessToken
|
||||||
|
|
||||||
|
const db = get(DataBase)
|
||||||
|
db.novelai.token = data
|
||||||
|
|
||||||
|
alertNormal('Logged in to NovelAI')
|
||||||
|
setDatabase(db)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
error = (`Failed to authenticate with NovelAI: ${error}`)
|
||||||
|
tries++
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
if ((!r.ok) || (!r.data?.accessToken)) {
|
|
||||||
alertError(`Failed to authenticate with NovelAI: ${r.data?.message ?? r.data}`)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
alertError(error)
|
||||||
const data = r.data?.accessToken
|
|
||||||
|
|
||||||
const db = get(DataBase)
|
|
||||||
db.novelai.token = data
|
|
||||||
|
|
||||||
alertNormal('Logged in to NovelAI')
|
|
||||||
setDatabase(db)
|
|
||||||
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alertError(`Failed to authenticate with NovelAI: ${error}`)
|
alertError(`Failed to authenticate with NovelAI: ${error}`)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user