dappconnect-sdks/packages/status-js/src/utils/generate-key-from-password.ts
Pavel e1c4f0591d
Use built-in PBKDF2 implementation for browsers (#295)
* add pbkdf2 browser implementation

* use webcrypto in pbkdf2

* rename pbkdf2 file

* use pbkdf2

* add changeset

* revert rename

* remove browser field from package.json

* use `resolve.alias` for pbkdf2 if test

* use `mode` in vite.config.ts

Co-authored-by: Felicio Mununga <felicio@users.noreply.github.com>
2022-07-19 17:45:29 +02:00

21 lines
485 B
TypeScript

import { utf8ToBytes } from 'ethereum-cryptography/utils'
import { pbkdf2 } from '../crypto/pbkdf2.browser'
const AES_KEY_LENGTH = 32 // bytes
/**
* status-go: https://github.com/status-im/status-go/blob/a471fed6a64e01a1aba8d925377fba045a5aa9f9/wakuv2/waku.go#L713
*/
export async function generateKeyFromPassword(
password: string
): Promise<Uint8Array> {
return await pbkdf2(
utf8ToBytes(password),
utf8ToBytes(''),
65356,
AES_KEY_LENGTH,
'sha256'
)
}