Merge pull request #15 from orbitdb/refactor/new-keys

Add new test keys fixtures database
This commit is contained in:
Hayden Young 2023-03-01 21:13:55 +08:00 committed by GitHub
commit ddf56a186f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 108 additions and 152 deletions

View File

@ -16,7 +16,7 @@ const supportedTypes = {
}
const Identities = async ({ keystore, identityKeysPath, storage, ipfs } = {}) => {
keystore = keystore || await KeyStore({ storage: LevelStorage(identityKeysPath || DefaultIdentityKeysPath), valueEncoding: 'json' })
keystore = keystore || await KeyStore({ storage: await LevelStorage(identityKeysPath || DefaultIdentityKeysPath), valueEncoding: 'json' })
storage = storage || (ipfs ? await IPFSBlockStorage({ ipfs, pin: true }) : await MemoryStorage())
const verifiedIdentitiesCache = await LRUStorage({ size: 1000 })

View File

@ -33,6 +33,7 @@ const verifySignature = async (signature, publicKey, data) => {
} catch (e) {
// Catch error: sig length wrong
}
return Promise.resolve(res)
}
@ -67,12 +68,7 @@ const verifyMessage = async (signature, publicKey, data) => {
}
} else {
const compare = (cached, data) => {
/* let match
if (v === 'v0') {
match = Buffer.compare(Buffer.alloc(30, cached), Buffer.alloc(30, data)) === 0
} else { */
const match = Buffer.isBuffer(data) ? Buffer.compare(cached, data) === 0 : cached === data
// }
const match = Buffer.isBuffer(data) ? Buffer.compare(cached, data) === 0 : cached.toString() === data.toString()
return match
}
res = cached.publicKey === publicKey && compare(cached.data, data)
@ -80,18 +76,14 @@ const verifyMessage = async (signature, publicKey, data) => {
return res
}
// const verifiedCache = new LRU(1000)
const KeyStore = async ({ storage } = {}) => {
storage = storage || await ComposedStorage(await LevelStorage({ path: './keystore', valueEncoding: 'json' }), await LRUStorage({ size: 1000 }))
const KeyStore = async ({ storage, path } = {}) => {
storage = storage || await ComposedStorage(await LevelStorage({ path: path || './keystore' }), await LRUStorage({ size: 1000 }))
const close = async () => {
if (!storage) return
await storage.close()
}
const clear = async () => {
if (!storage) return
await storage.clear()
}
@ -99,13 +91,10 @@ const KeyStore = async ({ storage } = {}) => {
if (!id) {
throw new Error('id needed to check a key')
}
if (storage.status && storage.status !== 'open') {
return null
}
let hasKey = false
try {
const storedKey = await storage.get(id)
const storedKey = await storage.get('private_' + id)
hasKey = storedKey !== undefined && storedKey !== null
} catch (e) {
// Catches 'Error: ENOENT: no such file or directory, open <path>'
@ -117,7 +106,8 @@ const KeyStore = async ({ storage } = {}) => {
const addKey = async (id, key) => {
try {
await storage.put(id, JSON.stringify(key))
await storage.put('public_' + id, key.publicKey)
await storage.put('private_' + id, key.privateKey)
} catch (e) {
console.log(e)
}
@ -127,10 +117,6 @@ const KeyStore = async ({ storage } = {}) => {
if (!id) {
throw new Error('id needed to create a key')
}
// if (storage.status && storage.status !== 'open') {
// console.log("22::", id)
// return null
// }
// Generate a private key
const pair = await crypto.keys.generateKeyPair('secp256k1')
@ -139,8 +125,8 @@ const KeyStore = async ({ storage } = {}) => {
const decompressedKey = secp256k1.publicKeyConvert(Buffer.from(pubKey), false)
const key = {
publicKey: Buffer.from(decompressedKey).toString('hex'),
privateKey: Buffer.from(keys.marshal()).toString('hex')
publicKey: Buffer.from(decompressedKey),//.toString('hex'),
privateKey: Buffer.from(keys.marshal())//.toString('hex')
}
await addKey(id, key)
@ -153,13 +139,9 @@ const KeyStore = async ({ storage } = {}) => {
throw new Error('id needed to get a key')
}
if (storage.status && storage.status !== 'open') {
return null
}
let storedKey
try {
storedKey = await storage.get(id)
storedKey = await storage.get('private_' + id)
} catch (e) {
// ignore ENOENT error
}
@ -168,13 +150,8 @@ const KeyStore = async ({ storage } = {}) => {
return
}
const deserializedKey = JSON.parse(storedKey)
if (!deserializedKey) {
return
}
return unmarshal(Buffer.from(deserializedKey.privateKey, 'hex'))
// return unmarshal(Buffer.from(deserializedKey.privateKey, 'hex'))
return unmarshal(storedKey)
}
const getPublic = (keys, options = {}) => {

View File

@ -79,14 +79,14 @@ Object.keys(testAPIs).forEach((IPFS) => {
})
it('sets a key/value pair', async () => {
const expected = 'zdpuAyRbzMUs1v7B1gqRRHe6rnxwYbHKzDhxh3rJanEjoucHt'
const expected = 'zdpuAuXyxGeC6QC2rykxcdZFUoyRromkc9zMHz3LwLHxVVz2x'
const actual = await db.set('key1', 'value1')
strictEqual(actual, expected)
})
it('puts a key/value pair', async () => {
const expected = 'zdpuAyRbzMUs1v7B1gqRRHe6rnxwYbHKzDhxh3rJanEjoucHt'
const expected = 'zdpuAuXyxGeC6QC2rykxcdZFUoyRromkc9zMHz3LwLHxVVz2x'
const actual = await db.put('key1', 'value1')
strictEqual(actual, expected)

View File

@ -80,14 +80,14 @@ Object.keys(testAPIs).forEach((IPFS) => {
})
it('sets a key/value pair', async () => {
const expected = 'zdpuAyRbzMUs1v7B1gqRRHe6rnxwYbHKzDhxh3rJanEjoucHt'
const expected = 'zdpuAuXyxGeC6QC2rykxcdZFUoyRromkc9zMHz3LwLHxVVz2x'
const actual = await db.set('key1', 'value1')
strictEqual(actual, expected)
})
it('puts a key/value pair', async () => {
const expected = 'zdpuAyRbzMUs1v7B1gqRRHe6rnxwYbHKzDhxh3rJanEjoucHt'
const expected = 'zdpuAuXyxGeC6QC2rykxcdZFUoyRromkc9zMHz3LwLHxVVz2x'
const actual = await db.put('key1', 'value1')
strictEqual(actual, expected)

BIN
test/fixtures/newtestkeys2/001232.ldb vendored Normal file

Binary file not shown.

0
test/fixtures/newtestkeys2/001274.log vendored Normal file
View File

1
test/fixtures/newtestkeys2/CURRENT vendored Normal file
View File

@ -0,0 +1 @@
MANIFEST-001273

0
test/fixtures/newtestkeys2/LOCK vendored Normal file
View File

3
test/fixtures/newtestkeys2/LOG vendored Normal file
View File

@ -0,0 +1,3 @@
2023/03/01-14:41:38.623433 17234f000 Recovering log #1272
2023/03/01-14:41:38.623903 17234f000 Delete type=3 #1271
2023/03/01-14:41:38.623944 17234f000 Delete type=0 #1272

3
test/fixtures/newtestkeys2/LOG.old vendored Normal file
View File

@ -0,0 +1,3 @@
2023/03/01-14:41:38.531437 173b67000 Recovering log #1270
2023/03/01-14:41:38.531817 173b67000 Delete type=3 #1269
2023/03/01-14:41:38.531856 173b67000 Delete type=0 #1270

Binary file not shown.

View File

@ -3,6 +3,7 @@ import { Identities } from '../../src/identities/index.js'
import rimraf from 'rimraf'
const { sync: rmrf } = rimraf
import testKeysPath from './test-keys-path.js '
import userA from "./keys/identity-keys/03e0480538c2a39951d054e17ff31fde487cb1031d0044a037b53ad2e028a3e77c.json" assert { type: "json" }
import userB from "./keys/identity-keys/0358df8eb5def772917748fdf8a8b146581ad2041eae48d66cc6865f11783499a6.json" assert { type: "json" }
@ -29,16 +30,17 @@ const signingKeys = {
}
const createTestIdentities = async (ipfs1, ipfs2) => {
rmrf('./keys_1')
// rmrf('./keys_1')
const keystore = await KeyStore()
for (const [key, value] of Object.entries(identityKeys)) {
await keystore.addKey(key, value)
}
// const keystore = await KeyStore()
const keystore = await KeyStore({ path: testKeysPath })
// for (const [key, value] of Object.entries(identityKeys)) {
// await keystore.addKey(key, value)
// }
for (const [key, value] of Object.entries(signingKeys)) {
await keystore.addKey(key, value)
}
// for (const [key, value] of Object.entries(signingKeys)) {
// await keystore.addKey(key, value)
// }
// Create an identity for each peers
const identities1 = await Identities({ keystore, ipfs: ipfs1 })

1
test/fixtures/test-keys-path.js vendored Normal file
View File

@ -0,0 +1 @@
export default './test/fixtures/newtestkeys2'

View File

@ -9,6 +9,7 @@ import fs from 'fs-extra'
const fixturesPath = path.resolve('./test/identities/fixtures/keys')
const savedKeysPath = path.resolve('./test/identities/fixtures/savedKeys')
const identityKeysPath = path.resolve('./test/identities/identityKeys')
import testKeysPath from '../fixtures/test-keys-path.js '
const type = 'orbitdb'
describe('Identities', function () {
@ -21,7 +22,7 @@ describe('Identities', function () {
})
describe('Creating Identities', () => {
const id = 'A'
const id = 'userA'
let identities
let identity
@ -42,7 +43,7 @@ describe('Identities', function () {
})
describe('Get Identity', () => {
const id = 'A'
const id = 'userA'
let identities
let identity
@ -67,17 +68,15 @@ describe('Identities', function () {
})
})
describe('Passing in custom keystore', async () => {
const id = 'B'
describe.skip('Passing in custom keystore', async () => {
const id = 'userB'
let identity
let identities
let keystore
before(async () => {
const storage = await LevelStorage({ path: identityKeysPath, valueEncoding: 'json' })
keystore = await KeyStore({ storage })
keystore = await KeyStore({ path: testKeysPath })
identities = await Identities({ keystore })
})
@ -132,20 +131,18 @@ describe('Identities', function () {
})
describe('create an identity with saved keys', () => {
const id = 'QmPhnEjVkYE1Ym7F5MkRUfkD6NtuSptE7ugu1Ggr149W2X'
const id = 'userX'
const expectedPublicKey = '040d78ff62afb656ac62db1aae3b1536a614991e28bb4d721498898b7d4194339640cd18c37b259e2c77738de0d6f9a5d52e0b936611de6b6ba78891a8b2a38317'
const expectedIdSignature = '30450221009de7b91952d73f577e85962aa6301350865212e3956862f80f4ebb626ffc126b022027d57415fb145b7e06cf06320fbfa63ea98a958b065726fe86eaab809a6bf607'
const expectedPkIdSignature = '304402202806e7c2406ca1f35961d38adc3997c179e142d54e1ca838ace373fae27124fd02200d6ca3aea6e1341bf5e4e0b84b559bbeefecfade34115de266a69d04d924905e'
const expectedPublicKey = '0442fa42a69135eade1e37ea520bc8ee9e240efd62cb0edf0516b21258b4eae656241c40da462c95189b1ade83419138ca59845beb90d29b1be8542bde388ca5f9'
const expectedIdSignature = '3044022068b4bc360d127e39164fbc3b5184f5bd79cc5976286f793d9b38d1f2818e0259022027b875dc8c73635b32db72177b9922038ec4b1eabc8f1fd0919806b0b2519419'
const expectedPkIdSignature = '304402206d1aeff3a874b7bd83300219badf68bbcb514e2c60a7b40cec5f78ff2b7ba0f20220085f5f138730603418a0570ba12720f0a46997527bb4a077cd26b545e7811c31'
let identities
let identity
let savedKeysKeyStore
before(async () => {
await fs.copy(fixturesPath, savedKeysPath)
const storage = await LevelStorage({ path: savedKeysPath, valueEncoding: 'json' })
savedKeysKeyStore = await KeyStore({ storage })
savedKeysKeyStore = await KeyStore({ path: testKeysPath })
identities = await Identities({ keystore: savedKeysKeyStore })
identity = await identities.createIdentity({ id })
@ -198,8 +195,7 @@ describe('Identities', function () {
let keystore
before(async () => {
const storage = await LevelStorage({ path: identityKeysPath, valueEncoding: 'json' })
keystore = await KeyStore({ storage })
keystore = await KeyStore({ path: testKeysPath })
})
after(async () => {
@ -248,9 +244,7 @@ describe('Identities', function () {
let keystore
before(async () => {
const storage = await LevelStorage({ path: identityKeysPath, valueEncoding: 'json' })
keystore = await KeyStore({ storage })
keystore = await KeyStore({ path: testKeysPath })
identities = await Identities({ keystore })
})
@ -276,9 +270,7 @@ describe('Identities', function () {
let keystore
before(async () => {
const storage = await LevelStorage({ path: identityKeysPath, valueEncoding: 'json' })
keystore = await KeyStore({ storage })
keystore = await KeyStore({ path: testKeysPath })
identities = await Identities({ keystore })
identity = await identities.createIdentity({ id })
})
@ -322,8 +314,7 @@ describe('Identities', function () {
let signature
before(async () => {
const storage = await LevelStorage({ path: identityKeysPath, valueEncoding: 'json' })
keystore = await KeyStore({ storage })
keystore = await KeyStore({ path: testKeysPath })
})
after(async () => {

View File

@ -7,7 +7,9 @@ import { testAPIs } from 'orbit-db-test-utils'
import path from 'path'
import fs from 'fs-extra'
import rmrf from 'rimraf'
import { signingKeys } from './fixtures/orbit-db-identity-keys.js'
import { identityKeys, signingKeys } from './fixtures/orbit-db-identity-keys.js'
import { Identities } from '../src/identities/index.js'
import testKeysPath from './fixtures/test-keys-path.js '
Object.keys(testAPIs).forEach((IPFS) => {
describe('KeyStore (' + IPFS + ')', () => {
@ -15,11 +17,10 @@ Object.keys(testAPIs).forEach((IPFS) => {
describe('Creating and retrieving keys', () => {
beforeEach(async () => {
keystore = await KeyStore()
keystore = await KeyStore({ path: testKeysPath })
})
afterEach(async () => {
await keystore.clear()
await keystore.close()
})
@ -63,7 +64,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
})
it('returns false if key does not exist', async () => {
const id = 'key1'
const id = 'key1234567890'
const hasKey = await keystore.hasKey(id)
strictEqual(hasKey, false)
})
@ -116,7 +117,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
it('gets a non-existent key', async () => {
const expected = undefined
const id = 'key1'
const id = 'key111111111'
const actual = await keystore.getKey(id)
@ -125,29 +126,23 @@ Object.keys(testAPIs).forEach((IPFS) => {
})
describe('Using keys for signing and verifying', () => {
const fixturePath = path.join('test', 'fixtures', 'keys', 'signing-keys')
const storagePath = path.join('test', 'keys', 'signing-keys')
beforeEach(async () => {
await fs.copy(fixturePath, storagePath)
// load existing keystore
const storage = await LevelStorage({ path: storagePath, valueEncoding: 'json' })
const cache = await LRUStorage({ size: 1000 })
const composedStorage = await ComposedStorage(storage, cache)
keystore = await KeyStore({ storage: composedStorage })
keystore = await KeyStore({ path: testKeysPath })
// const identities = await Identities({ keystore })
// const a = await identities.createIdentity({ id: 'userA' })
// const b = await identities.createIdentity({ id: 'userB' })
// const c = await identities.createIdentity({ id: 'userC' })
// const d = await identities.createIdentity({ id: 'userD' })
// const x = await identities.createIdentity({ id: 'userX' })
})
afterEach(async () => {
await keystore.clear()
await keystore.close()
rmrf.sync(path.join('test', 'keys'))
})
describe('Signing', () => {
it('signs data', async () => {
const expected = '304402207eb6e4f4b2c56665c505696c41ec0831c6c2998620589d4b6f405d49134dea5102207e71ba37d94b7a70e3d9fb3bea7c8d8b7082c3c880b6831e9613a0a3e7aabd9f'
const expected = '3045022100df961fa46bb8a3cb92594a24205e6008a84daa563ac3530f583bb9f9cef5af3b02207b84c5d63387d0a710e42e05785fbccdaf2534c8ed16adb8afd57c3eba930529'
const key = await keystore.getKey('userA')
const actual = await signMessage(key, 'data data data')
@ -186,7 +181,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
})
it('gets the public key', async () => {
const expected = '04e0480538c2a39951d054e17ff31fde487cb1031d0044a037b53ad2e028a3e77c34e864b8579e7c7b24542959e7325361a96f1efb41ed5d3c08f0ea1e5dd0c8ed'
const expected = '04e7247a4c155b63d182a23c70cb6fe8ba2e44bc9e9d62dc45d4c4167ccde95944f13db3c707da2ee0e3fd6ba531caef9f86eb79132023786cd6139ec5ebed4fae'
const publicKey = await keystore.getPublic(key)
strictEqual(publicKey, expected)
})
@ -194,12 +189,14 @@ Object.keys(testAPIs).forEach((IPFS) => {
it('gets the public key buffer', async () => {
const expected = {
type: 'Buffer',
data: [4, 224, 72, 5, 56, 194, 163, 153, 81, 208, 84,
225, 127, 243, 31, 222, 72, 124, 177, 3, 29, 0,
68, 160, 55, 181, 58, 210, 224, 40, 163, 231, 124,
52, 232, 100, 184, 87, 158, 124, 123, 36, 84, 41,
89, 231, 50, 83, 97, 169, 111, 30, 251, 65, 237,
93, 60, 8, 240, 234, 30, 93, 208, 200, 237]
data: [
4, 231, 36, 122, 76, 21, 91, 99, 209, 130, 162,
60, 112, 203, 111, 232, 186, 46, 68, 188, 158, 157,
98, 220, 69, 212, 196, 22, 124, 205, 233, 89, 68,
241, 61, 179, 199, 7, 218, 46, 224, 227, 253, 107,
165, 49, 202, 239, 159, 134, 235, 121, 19, 32, 35,
120, 108, 214, 19, 158, 197, 235, 237, 79, 174
]
}
const publicKey = await keystore.getPublic(key, { format: 'buffer' })
@ -207,7 +204,8 @@ Object.keys(testAPIs).forEach((IPFS) => {
})
it('gets the public key when decompress is false', async () => {
const expectedCompressedKey = signingKeys.userA.publicKey
// const expectedCompressedKey = signingKeys.userA.publicKey
const expectedCompressedKey = '02e7247a4c155b63d182a23c70cb6fe8ba2e44bc9e9d62dc45d4c4167ccde95944'
const publicKey = await keystore.getPublic(key, { decompress: false })
strictEqual(publicKey, expectedCompressedKey)
})
@ -215,11 +213,13 @@ Object.keys(testAPIs).forEach((IPFS) => {
it('gets the public key buffer when decompressed is false', async () => {
const expected = {
type: 'Buffer',
data: [3, 224, 72, 5, 56, 194, 163, 153,
81, 208, 84, 225, 127, 243, 31, 222,
72, 124, 177, 3, 29, 0, 68, 160,
55, 181, 58, 210, 224, 40, 163, 231,
124]
data: [
2, 231, 36, 122, 76, 21, 91, 99,
209, 130, 162, 60, 112, 203, 111, 232,
186, 46, 68, 188, 158, 157, 98, 220,
69, 212, 196, 22, 124, 205, 233, 89,
68
]
}
const publicKey = await keystore.getPublic(key, { format: 'buffer', decompress: false })
@ -253,8 +253,11 @@ Object.keys(testAPIs).forEach((IPFS) => {
})
it('verifies content', async () => {
const signature = '304402207eb6e4f4b2c56665c505696c41ec0831c6c2998620589d4b6f405d49134dea5102207e71ba37d94b7a70e3d9fb3bea7c8d8b7082c3c880b6831e9613a0a3e7aabd9f'
const verified = await verifyMessage(signature, publicKey, 'data data data')
const signature = await signMessage(key, 'data data data')
const expectedSignature = '3045022100df961fa46bb8a3cb92594a24205e6008a84daa563ac3530f583bb9f9cef5af3b02207b84c5d63387d0a710e42e05785fbccdaf2534c8ed16adb8afd57c3eba930529'
strictEqual(expectedSignature, signature)
const verified = await verifyMessage(expectedSignature, publicKey, 'data data data')
strictEqual(verified, true)
})

View File

@ -5,9 +5,9 @@ import { Log } from '../../src/oplog/index.js'
import { Identities } from '../../src/identities/index.js'
import KeyStore from '../../src/key-store.js'
import MemoryStorage from '../../src/storage/memory.js'
// Test utils
import LevelStorage from '../../src/storage/level.js'
import { config, testAPIs } from 'orbit-db-test-utils'
import testKeysPath from '../fixtures/test-keys-path.js '
const { sync: rmrf } = rimraf
const { createIdentity } = Identities
@ -24,20 +24,14 @@ Object.keys(testAPIs).forEach((IPFS) => {
let identities1, identities2, identities3
before(async () => {
rmrf(identityKeysPath)
await copy(identityKeyFixtures, identityKeysPath)
await copy(signingKeyFixtures, identityKeysPath)
keystore = await KeyStore({ storage: await LevelStorage({ path: identityKeysPath }) })
keystore = await KeyStore({ path: testKeysPath })
const storage = await MemoryStorage()
identities1 = await Identities({ keystore, storage })
identities2 = await Identities({ keystore, storage })
identities3 = await Identities({ keystore, storage })
identities1 = await Identities({ keystore })
testIdentity = await identities1.createIdentity({ id: 'userA' })
testIdentity2 = await identities2.createIdentity({ id: 'userB' })
testIdentity3 = await identities3.createIdentity({ id: 'userC' })
testIdentity2 = await identities1.createIdentity({ id: 'userB' })
testIdentity3 = await identities1.createIdentity({ id: 'userC' })
})
after(async () => {

View File

@ -6,8 +6,7 @@ import { Identities } from '../../src/identities/index.js'
import KeyStore from '../../src/key-store.js'
import LevelStorage from '../../src/storage/level.js'
import { config, testAPIs, startIpfs, stopIpfs } from 'orbit-db-test-utils'
// import IdentityStorage from '../src/identity-storage.js'
// import IPFSBlockStorage from '../src/ipfs-block-storage.js'
import testKeysPath from '../fixtures/test-keys-path.js '
const { sync: rmrf } = rimraf
const { createIdentity } = Identities
@ -31,8 +30,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
await copy(identityKeyFixtures, identityKeysPath)
await copy(signingKeyFixtures, identityKeysPath)
const storage = await LevelStorage({ path: identityKeysPath, valueEncoding: 'json' })
keystore = await KeyStore({ storage })
keystore = await KeyStore({ path: testKeysPath })
identities = await Identities({ keystore, ipfs })
testIdentity = await identities.createIdentity({ id: 'userA' })

View File

@ -5,9 +5,8 @@ import { Log } from '../../src/oplog/index.js'
import { Identities } from '../../src/identities/index.js'
import KeyStore from '../../src/key-store.js'
import MemoryStorage from '../../src/storage/memory.js'
// Test utils
import { config, testAPIs } from 'orbit-db-test-utils'
import testKeysPath from '../fixtures/test-keys-path.js '
const { sync: rmrf } = rimraf
const { createIdentity } = Identities
@ -33,7 +32,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
await copy(identityKeyFixtures, identityKeysPath)
await copy(signingKeyFixtures, identityKeysPath)
keystore = await KeyStore({ storage: await LevelStorage({ path: identityKeysPath }) })
keystore = await KeyStore({ path: testKeysPath })
const storage = await MemoryStorage()
identities = await Identities({ keystore, storage })

View File

@ -6,12 +6,10 @@ import { Identities } from '../../src/identities/index.js'
import KeyStore from '../../src/key-store.js'
import LevelStorage from '../../src/storage/level.js'
import MemoryStorage from '../../src/storage/memory.js'
// Test utils
import { config, testAPIs } from 'orbit-db-test-utils'
import testKeysPath from '../fixtures/test-keys-path.js '
const { sync: rmrf } = rimraf
const { createIdentity } = Identities
let testIdentity, testIdentity2
@ -25,24 +23,15 @@ Object.keys(testAPIs).forEach(IPFS => {
let identities1, identities2
before(async () => {
rmrf(identityKeysPath)
keystore = await KeyStore({ path: testKeysPath })
await copy(identityKeyFixtures, identityKeysPath)
await copy(signingKeyFixtures, identityKeysPath)
keystore = await KeyStore({ storage: await LevelStorage({ path: identityKeysPath, valueEncoding: 'json' }) })
const storage = await MemoryStorage()
identities1 = await Identities({ keystore, storage })
identities2 = await Identities({ keystore, storage })
identities1 = await Identities({ keystore })
testIdentity = await identities1.createIdentity({ id: 'userA' })
testIdentity2 = await identities2.createIdentity({ id: 'userB' })
testIdentity2 = await identities1.createIdentity({ id: 'userB' })
})
after(async () => {
await keystore.close()
rmrf(identityKeysPath)
})
describe('join ', async () => {

View File

@ -6,9 +6,8 @@ import KeyStore from '../../src/key-store.js'
import { copy } from 'fs-extra'
import LevelStorage from '../../src/storage/level.js'
import MemoryStorage from '../../src/storage/memory.js'
// Test utils
import { config, testAPIs } from 'orbit-db-test-utils'
import testKeysPath from '../fixtures/test-keys-path.js '
const { sync: rmrf } = rimraf
const { create } = Entry
@ -29,7 +28,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
await copy(identityKeyFixtures, identityKeysPath)
await copy(signingKeyFixtures, identityKeysPath)
keystore = await KeyStore({ storage: await LevelStorage({ path: identityKeysPath, valueEncoding: 'json' }) })
keystore = await KeyStore({ path: testKeysPath })
const storage = await MemoryStorage()

View File

@ -6,8 +6,7 @@ import { Identities } from '../../src/identities/index.js'
import KeyStore from '../../src/key-store.js'
import LevelStorage from '../../src/storage/level.js'
import MemoryStorage from '../../src/storage/memory.js'
// Test utils
import testKeysPath from '../fixtures/test-keys-path.js '
import { config, testAPIs } from 'orbit-db-test-utils'
const { sync: rmrf } = rimraf
@ -30,7 +29,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
await copy(identityKeyFixtures, identityKeysPath)
await copy(signingKeyFixtures, identityKeysPath)
keystore = await KeyStore({ storage: await LevelStorage({ path: identityKeysPath, valueEncoding: 'json' }) })
keystore = await KeyStore({ path: testKeysPath })
const storage = await MemoryStorage()

View File

@ -6,9 +6,8 @@ import { Identities } from '../src/identities/index.js'
import KeyStore from '../src/key-store.js'
import { IPFSBlockStorage, MemoryStorage, LRUStorage, ComposedStorage, LevelStorage } from '../src/storage/index.js'
import { copy } from 'fs-extra'
// Test utils
import { config, testAPIs } from 'orbit-db-test-utils'
import testKeysPath from './fixtures/test-keys-path.js '
const { sync: rmrf } = rimraf
const { createIdentity } = Identities
@ -34,7 +33,7 @@ Object.keys(testAPIs).forEach((_) => {
// Start an IPFS instance
ipfs1 = await IPFS.create({ ...config.daemon1, repo: './ipfs1' })
keystore = await KeyStore({ storage: await LevelStorage({ path: identityKeysPath, valueEncoding: 'json' }) })
keystore = await KeyStore({ path: testKeysPath })
const storage = await MemoryStorage()
const identities = await Identities({ keystore, storage })
@ -48,8 +47,6 @@ Object.keys(testAPIs).forEach((_) => {
if (keystore) {
await keystore.close()
}
rmrf(identityKeysPath)
rmrf(testIdentity1.id)
rmrf('./ipfs1')
rmrf('./orbitdb')
})