Fix seed and update translations

This commit is contained in:
AlphaX-Projects
2023-06-27 16:21:06 +02:00
parent e87fcff260
commit 8bfc0a850c
22 changed files with 450 additions and 31 deletions

View File

@@ -1,23 +1,32 @@
import Base58 from './deps/Base58.js'
import { kdf } from './kdf.js'
import { HmacSha512, AES_CBC } from 'asmcrypto.js'
import { use, get, translate, translateUnsafeHTML, registerTranslateConfig } from 'lit-translate'
registerTranslateConfig({
loader: lang => fetch(`/language/${lang}.json`).then(res => res.json())
})
export const decryptStoredWallet = async (password, wallet, statusFn = () => { }) => {
statusFn('Decoding saved data')
const sfn1 = get("login.lp12")
statusFn(sfn1)
const encryptedSeedBytes = Base58.decode(wallet.encryptedSeed)
const iv = Base58.decode(wallet.iv)
const salt = Base58.decode(wallet.salt)
statusFn('Generating decryption key')
const sfn2 = get("login.lp13")
statusFn(sfn2)
const key = await kdf(password, salt, statusFn)
const encryptionKey = key.slice(0, 32)
const macKey = key.slice(32, 63)
statusFn('Checking key')
const sfn3 = get("login.lp14")
statusFn(sfn3)
const mac = new HmacSha512(macKey).process(encryptedSeedBytes).finish().result
const sfn4 = get("login.lp15")
if (Base58.encode(mac) !== wallet.mac) {
throw new Error('Incorrect password')
throw new Error(sfn4)
}
statusFn('Decrypting')
const sfn5 = get("login.lp16")
statusFn(sfn5)
const decryptedBytes = AES_CBC.decrypt(encryptedSeedBytes, encryptionKey, false, iv)
return decryptedBytes
}

View File

@@ -2,14 +2,21 @@ import { store } from '../api_deps.js'
import { stateAwait } from './utils/stateAwait.js'
import { Sha512 } from 'asmcrypto.js'
import utils from '../api/deps/utils.js'
import { use, get, translate, translateUnsafeHTML, registerTranslateConfig } from 'lit-translate'
registerTranslateConfig({
loader: lang => fetch(`/language/${lang}.json`).then(res => res.json())
})
export const kdf = async (seed, salt, status = () => { }) => {
const state = store.getState()
const config = state.config
const workers = state.app.workers.workers
status('Waiting for workers to be ready')
const kst1 = get("login.lp17")
status(kst1)
await stateAwait(state => state.app.workers.ready)
status('Deriving key parts')
const kst2 = get("login.lp18")
status(kst2)
salt = new Uint8Array(salt)
const seedParts = await Promise.all(workers.map((worker, index) => {
const nonce = index
@@ -27,13 +34,17 @@ export const kdf = async (seed, salt, status = () => { }) => {
} catch (e) {
// ...
}
if (seed !== data.key) throw new Error('Error, incorrect key. ' + seed + ' !== ' + data.key)
if (nonce !== data.nonce) throw new Error('Error, incorrect nonce')
const kst3 = get("login.lp19")
if (seed !== data.key) throw new Error(kst3 + seed + ' !== ' + data.key)
const kst4 = get("login.lp20")
if (nonce !== data.nonce) throw new Error(kst4)
return data.result
})
}))
status('Combining key parts')
const kst5 = get("login.lp21")
status(kst5)
const result = new Sha512().process(utils.stringtoUTF8Array(config.crypto.staticSalt + seedParts.reduce((a, c) => a + c))).finish().result
status('Key is ready ')
const kst6 = get("login.lp22")
status(kst6)
return result
}