refactor: Store identity hash against each entry.

This commit is contained in:
Hayden Young 2023-02-09 11:26:27 +00:00 committed by haad
parent 2d425f7323
commit d5235ef23d
3 changed files with 15 additions and 3 deletions

View File

@ -48,8 +48,10 @@ const create = async (identity, id, payload, clock = null, next = [], refs = [])
const { bytes } = await Block.encode({ value: entry, codec, hasher })
const signature = await identity.provider.sign(identity, bytes)
const { cid } = await Block.encode({ value: identity.toJSON(), codec, hasher })
entry.key = identity.publicKey
entry.identity = identity.toJSON()
entry.identity = cid.toString(hashStringEncoding)
entry.sig = signature
return _encodeEntry(entry)

View File

@ -4,6 +4,8 @@ import { base58btc } from 'multiformats/bases/base58'
const defaultTimeout = 30000
const IPFSBlockStorage = async ({ ipfs, timeout, pin } = {}) => {
if (!ipfs) throw new Error('An instance of ipfs is required.')
timeout = timeout || defaultTimeout
const put = async (hash, data) => {

View File

@ -4,7 +4,7 @@ import { copy } from 'fs-extra'
import Entry from '../src/entry.js'
import IdentityProvider from 'orbit-db-identity-provider'
import Keystore from '../src/Keystore.js'
import { config, testAPIs } from 'orbit-db-test-utils'
import { config, testAPIs, startIpfs, stopIpfs } from 'orbit-db-test-utils'
const { sync: rmrf } = rimraf
const { createIdentity } = IdentityProvider
@ -18,15 +18,19 @@ Object.keys(testAPIs).forEach((IPFS) => {
let testIdentity
let keystore, signingKeystore
let ipfsd, ipfs
before(async () => {
ipfsd = await startIpfs(IPFS, config.daemon1)
ipfs = ipfsd.api
await copy(identityKeyFixtures, identityKeysPath)
await copy(signingKeyFixtures, signingKeysPath)
keystore = new Keystore(identityKeysPath)
signingKeystore = new Keystore(signingKeysPath)
testIdentity = await createIdentity({ id: 'userA', keystore, signingKeystore })
testIdentity = await createIdentity({ id: 'userA', keystore, signingKeystore, ipfs })
})
after(async () => {
@ -36,6 +40,10 @@ Object.keys(testAPIs).forEach((IPFS) => {
rmrf(signingKeysPath)
await keystore.close()
await signingKeystore.close()
if (ipfsd) {
await stopIpfs(ipfsd)
}
})
describe('create', () => {