Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions lib/hex.js

This file was deleted.

11 changes: 5 additions & 6 deletions wallets/client/hooks/crypto.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useCallback, useMemo, useState } from 'react'
import { fromHex, toHex } from '@/lib/hex'
import { useMe } from '@/components/me'
import { useIndexedDB } from '@/components/use-indexeddb'
import { useShowModal } from '@/components/modal'
Expand Down Expand Up @@ -307,7 +306,7 @@ export async function deriveKey (passphrase, salt) {
)

const rawKey = await window.crypto.subtle.exportKey('raw', key)
const hash = toHex(await window.crypto.subtle.digest('SHA-256', rawKey))
const hash = Buffer.from(await window.crypto.subtle.digest('SHA-256', rawKey)).toString('hex')
const unextractableKey = await window.crypto.subtle.importKey(
'raw',
rawKey,
Expand Down Expand Up @@ -338,19 +337,19 @@ async function _encrypt ({ key, hash }, value) {
)
return {
keyHash: hash,
iv: toHex(iv.buffer),
value: toHex(encrypted)
iv: Buffer.from(iv).toString('hex'),
value: Buffer.from(encrypted).toString('hex')
}
}

async function _decrypt (key, { iv, value }) {
const decrypted = await window.crypto.subtle.decrypt(
{
name: 'AES-GCM',
iv: fromHex(iv)
iv: Buffer.from(iv, 'hex')
},
key,
fromHex(value)
Buffer.from(value, 'hex')
)
const decoded = new TextDecoder().decode(decrypted)
return JSON.parse(decoded)
Expand Down