Skip to content

Commit 1b4b71a

Browse files
authored
Replace lib/hex with Buffer.from (#2585)
1 parent 612b4fd commit 1b4b71a

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/client/hooks/crypto.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { useCallback, useMemo, useState } from 'react'
2-
import { fromHex, toHex } from '@/lib/hex'
32
import { useMe } from '@/components/me'
43
import { useIndexedDB } from '@/components/use-indexeddb'
54
import { useShowModal } from '@/components/modal'
@@ -307,7 +306,7 @@ export async function deriveKey (passphrase, salt) {
307306
)
308307

309308
const rawKey = await window.crypto.subtle.exportKey('raw', key)
310-
const hash = toHex(await window.crypto.subtle.digest('SHA-256', rawKey))
309+
const hash = Buffer.from(await window.crypto.subtle.digest('SHA-256', rawKey)).toString('hex')
311310
const unextractableKey = await window.crypto.subtle.importKey(
312311
'raw',
313312
rawKey,
@@ -338,19 +337,19 @@ async function _encrypt ({ key, hash }, value) {
338337
)
339338
return {
340339
keyHash: hash,
341-
iv: toHex(iv.buffer),
342-
value: toHex(encrypted)
340+
iv: Buffer.from(iv).toString('hex'),
341+
value: Buffer.from(encrypted).toString('hex')
343342
}
344343
}
345344

346345
async function _decrypt (key, { iv, value }) {
347346
const decrypted = await window.crypto.subtle.decrypt(
348347
{
349348
name: 'AES-GCM',
350-
iv: fromHex(iv)
349+
iv: Buffer.from(iv, 'hex')
351350
},
352351
key,
353-
fromHex(value)
352+
Buffer.from(value, 'hex')
354353
)
355354
const decoded = new TextDecoder().decode(decrypted)
356355
return JSON.parse(decoded)

0 commit comments

Comments
 (0)