From d5235ef23d290cd0a1289855a0154f1a7d620740 Mon Sep 17 00:00:00 2001 From: Hayden Young Date: Thu, 9 Feb 2023 11:26:27 +0000 Subject: [PATCH] refactor: Store identity hash against each entry. --- src/entry.js | 4 +++- src/ipfs-block-storage.js | 2 ++ test/entry.spec.js | 12 ++++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/entry.js b/src/entry.js index 2786217..4f78855 100644 --- a/src/entry.js +++ b/src/entry.js @@ -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) diff --git a/src/ipfs-block-storage.js b/src/ipfs-block-storage.js index 0bd8cf4..b168b8d 100644 --- a/src/ipfs-block-storage.js +++ b/src/ipfs-block-storage.js @@ -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) => { diff --git a/test/entry.spec.js b/test/entry.spec.js index f1bc054..97f4e7f 100644 --- a/test/entry.spec.js +++ b/test/entry.spec.js @@ -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', () => {