mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-07-10 14:32:29 +00:00
20 lines
587 B
JavaScript
20 lines
587 B
JavaScript
import EthCrypto from 'eth-crypto'
|
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
|
|
const encrypt = ({ publicKey }) => async (value) => {
|
|
const encryptedObj = await EthCrypto.encryptWithPublicKey(publicKey, value)
|
|
return EthCrypto.cipher.stringify(encryptedObj)
|
|
}
|
|
|
|
const decrypt = ({ privateKey }) => async (value) => {
|
|
const privateKeyStr = uint8ArrayToString(privateKey.marshal(), 'base16')
|
|
|
|
const encryptedObj = EthCrypto.cipher.parse(value)
|
|
return await EthCrypto.decryptWithPrivateKey(privateKeyStr, encryptedObj)
|
|
}
|
|
|
|
export {
|
|
encrypt,
|
|
decrypt
|
|
}
|