mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-07-10 14:32:29 +00:00
feat: Explicitly specify public and private keys.
This commit is contained in:
parent
796308ca7f
commit
373d2d8414
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user