feat: Explicitly specify public and private keys.

This commit is contained in:
Hayden Young 2024-05-17 03:30:56 +01:00
parent 796308ca7f
commit 373d2d8414
2 changed files with 10 additions and 6 deletions

View File

@ -145,8 +145,13 @@ describe('Log', function () {
})
it('encrypts the value of an entry in the log', async () => {
const encryptFn = encrypt({ identity: testIdentity })
const decryptFn = decrypt({ identities, identity: testIdentity })
const keys = await keystore.createKey('hello1')
const privateKey = await keystore.getKey('hello1')
const publicKey = await keystore.getPublic(keys)
const encryptFn = encrypt({ publicKey })
const decryptFn = decrypt({ privateKey })
const log = await Log(testIdentity, { encryptFn, decryptFn })
const entry = await log.append('hello1')
const value = await log.get(entry.hash)

View File

@ -1,13 +1,12 @@
import EthCrypto from 'eth-crypto'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
const encrypt = ({ identity }) => async (value) => {
const encryptedObj = await EthCrypto.encryptWithPublicKey(identity.publicKey, value)
const encrypt = ({ publicKey }) => async (value) => {
const encryptedObj = await EthCrypto.encryptWithPublicKey(publicKey, value)
return EthCrypto.cipher.stringify(encryptedObj)
}
const decrypt = ({ identities, identity }) => async (value) => {
const privateKey = await identities.keystore.getKey(identity.id)
const decrypt = ({ privateKey }) => async (value) => {
const privateKeyStr = uint8ArrayToString(privateKey.marshal(), 'base16')
const encryptedObj = EthCrypto.cipher.parse(value)