mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-02 04:06:37 +00:00
refactor: Store identity hash against each entry.
This commit is contained in:
parent
2d425f7323
commit
d5235ef23d
@ -48,8 +48,10 @@ const create = async (identity, id, payload, clock = null, next = [], refs = [])
|
|||||||
const { bytes } = await Block.encode({ value: entry, codec, hasher })
|
const { bytes } = await Block.encode({ value: entry, codec, hasher })
|
||||||
const signature = await identity.provider.sign(identity, bytes)
|
const signature = await identity.provider.sign(identity, bytes)
|
||||||
|
|
||||||
|
const { cid } = await Block.encode({ value: identity.toJSON(), codec, hasher })
|
||||||
|
|
||||||
entry.key = identity.publicKey
|
entry.key = identity.publicKey
|
||||||
entry.identity = identity.toJSON()
|
entry.identity = cid.toString(hashStringEncoding)
|
||||||
entry.sig = signature
|
entry.sig = signature
|
||||||
|
|
||||||
return _encodeEntry(entry)
|
return _encodeEntry(entry)
|
||||||
|
@ -4,6 +4,8 @@ import { base58btc } from 'multiformats/bases/base58'
|
|||||||
const defaultTimeout = 30000
|
const defaultTimeout = 30000
|
||||||
|
|
||||||
const IPFSBlockStorage = async ({ ipfs, timeout, pin } = {}) => {
|
const IPFSBlockStorage = async ({ ipfs, timeout, pin } = {}) => {
|
||||||
|
if (!ipfs) throw new Error('An instance of ipfs is required.')
|
||||||
|
|
||||||
timeout = timeout || defaultTimeout
|
timeout = timeout || defaultTimeout
|
||||||
|
|
||||||
const put = async (hash, data) => {
|
const put = async (hash, data) => {
|
||||||
|
@ -4,7 +4,7 @@ import { copy } from 'fs-extra'
|
|||||||
import Entry from '../src/entry.js'
|
import Entry from '../src/entry.js'
|
||||||
import IdentityProvider from 'orbit-db-identity-provider'
|
import IdentityProvider from 'orbit-db-identity-provider'
|
||||||
import Keystore from '../src/Keystore.js'
|
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 { sync: rmrf } = rimraf
|
||||||
const { createIdentity } = IdentityProvider
|
const { createIdentity } = IdentityProvider
|
||||||
@ -18,15 +18,19 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
|||||||
|
|
||||||
let testIdentity
|
let testIdentity
|
||||||
let keystore, signingKeystore
|
let keystore, signingKeystore
|
||||||
|
let ipfsd, ipfs
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
|
ipfsd = await startIpfs(IPFS, config.daemon1)
|
||||||
|
ipfs = ipfsd.api
|
||||||
|
|
||||||
await copy(identityKeyFixtures, identityKeysPath)
|
await copy(identityKeyFixtures, identityKeysPath)
|
||||||
await copy(signingKeyFixtures, signingKeysPath)
|
await copy(signingKeyFixtures, signingKeysPath)
|
||||||
|
|
||||||
keystore = new Keystore(identityKeysPath)
|
keystore = new Keystore(identityKeysPath)
|
||||||
signingKeystore = new Keystore(signingKeysPath)
|
signingKeystore = new Keystore(signingKeysPath)
|
||||||
|
|
||||||
testIdentity = await createIdentity({ id: 'userA', keystore, signingKeystore })
|
testIdentity = await createIdentity({ id: 'userA', keystore, signingKeystore, ipfs })
|
||||||
})
|
})
|
||||||
|
|
||||||
after(async () => {
|
after(async () => {
|
||||||
@ -36,6 +40,10 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
|||||||
rmrf(signingKeysPath)
|
rmrf(signingKeysPath)
|
||||||
await keystore.close()
|
await keystore.close()
|
||||||
await signingKeystore.close()
|
await signingKeystore.close()
|
||||||
|
|
||||||
|
if (ipfsd) {
|
||||||
|
await stopIpfs(ipfsd)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('create', () => {
|
describe('create', () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user