Skip to content

Commit e299459

Browse files
committed
Replace lib/hex with Buffer.from
1 parent 81ee01c commit e299459

File tree

2 files changed

+5
-26
lines changed

2 files changed

+5
-26
lines changed

lib/hex.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

wallets/lib/crypto.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import bip39Words from '@/lib/bip39-words'
2-
import { fromHex, toHex } from '@/lib/hex'
32

43
export async function deriveKey (passphrase, salt) {
54
const enc = new TextEncoder()
@@ -28,7 +27,7 @@ export async function deriveKey (passphrase, salt) {
2827
)
2928

3029
const rawKey = await window.crypto.subtle.exportKey('raw', key)
31-
const hash = toHex(await window.crypto.subtle.digest('SHA-256', rawKey))
30+
const hash = Buffer.from(await window.crypto.subtle.digest('SHA-256', rawKey)).toString('hex')
3231
const unextractableKey = await window.crypto.subtle.importKey(
3332
'raw',
3433
rawKey,
@@ -59,19 +58,19 @@ export async function encrypt ({ key, hash }, value) {
5958
)
6059
return {
6160
keyHash: hash,
62-
iv: toHex(iv.buffer),
63-
value: toHex(encrypted)
61+
iv: Buffer.from(iv).toString('hex'),
62+
value: Buffer.from(encrypted).toString('hex')
6463
}
6564
}
6665

6766
export async function decrypt (key, { iv, value }) {
6867
const decrypted = await window.crypto.subtle.decrypt(
6968
{
7069
name: 'AES-GCM',
71-
iv: fromHex(iv)
70+
iv: Buffer.from(iv, 'hex')
7271
},
7372
key,
74-
fromHex(value)
73+
Buffer.from(value, 'hex')
7574
)
7675
const decoded = new TextDecoder().decode(decrypted)
7776
return JSON.parse(decoded)

0 commit comments

Comments
 (0)