From 1575f00912d28db382f8e777aa2e8161576220e3 Mon Sep 17 00:00:00 2001 From: haad Date: Wed, 1 Mar 2023 14:42:58 +0200 Subject: [PATCH] Add new test keys fixtures database --- src/identities/identities.js | 2 +- src/key-store.js | 47 ++++---------- test/db/keyvalue-persisted.js | 4 +- test/db/keyvalue.test.js | 4 +- test/fixtures/newtestkeys2/001232.ldb | Bin 0 -> 3272 bytes test/fixtures/newtestkeys2/001274.log | 0 test/fixtures/newtestkeys2/CURRENT | 1 + test/fixtures/newtestkeys2/LOCK | 0 test/fixtures/newtestkeys2/LOG | 3 + test/fixtures/newtestkeys2/LOG.old | 3 + test/fixtures/newtestkeys2/MANIFEST-001273 | Bin 0 -> 185 bytes test/fixtures/orbit-db-identity-keys.js | 18 +++--- test/fixtures/test-keys-path.js | 1 + test/identities/identities.test.js | 39 +++++------ test/key-store.test.js | 71 +++++++++++---------- test/oplog/crdt.test.js | 18 ++---- test/oplog/entry.test.js | 8 +-- test/oplog/heads.test.js | 5 +- test/oplog/join-concurrent.test.js | 19 ++---- test/oplog/log.test.js | 5 +- test/oplog/references.test.js | 5 +- test/storage.spec.js | 7 +- 22 files changed, 108 insertions(+), 152 deletions(-) create mode 100644 test/fixtures/newtestkeys2/001232.ldb create mode 100644 test/fixtures/newtestkeys2/001274.log create mode 100644 test/fixtures/newtestkeys2/CURRENT create mode 100644 test/fixtures/newtestkeys2/LOCK create mode 100644 test/fixtures/newtestkeys2/LOG create mode 100644 test/fixtures/newtestkeys2/LOG.old create mode 100644 test/fixtures/newtestkeys2/MANIFEST-001273 create mode 100644 test/fixtures/test-keys-path.js diff --git a/src/identities/identities.js b/src/identities/identities.js index 6371548..cc08e3d 100644 --- a/src/identities/identities.js +++ b/src/identities/identities.js @@ -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 }) diff --git a/src/key-store.js b/src/key-store.js index 8ec3b95..becac4d 100644 --- a/src/key-store.js +++ b/src/key-store.js @@ -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 ' @@ -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 = {}) => { diff --git a/test/db/keyvalue-persisted.js b/test/db/keyvalue-persisted.js index 3ce2874..0e12967 100644 --- a/test/db/keyvalue-persisted.js +++ b/test/db/keyvalue-persisted.js @@ -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) diff --git a/test/db/keyvalue.test.js b/test/db/keyvalue.test.js index a8ade8e..ff72727 100644 --- a/test/db/keyvalue.test.js +++ b/test/db/keyvalue.test.js @@ -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) diff --git a/test/fixtures/newtestkeys2/001232.ldb b/test/fixtures/newtestkeys2/001232.ldb new file mode 100644 index 0000000000000000000000000000000000000000..a3df6b5e38fcd792f7a757d971a7d7c02d7d8dbb GIT binary patch literal 3272 zcmb_edpK438n#Da6S+j9%&y!@SogJ;8EU(gp^S)-w5}3zzfDo0RJzcq(bRS;%+x_M z)YPbm(B#rd$t2fG5)GL&rHjsD@AKz*p7T7;`fu&u_j}*>yX^N{3hPA?QNeL!3>yeQ zfEa@@n4m$NfN6$?A(G-angnSAfH?wVATh+SC<+541%nvQU>Hb~`~f9~a2O+K!5oF@ zCqvzC^Wc%5B5+-!!C>3Olep_Q4%X0>Ug|fs1+LylaMd*;m;qT1CqaaP7=*_MNsfX^ z2tmX+N)uu+hp;>#&At}X zq--0ySS#O@_%oJqzBeN{o{G-{qHva>5QJmJEWja*n85*#rNksb!vF;XI0S+qK*A`> z(gX(q0EMs!K_VE8Gl;-kMy2M^=y@gG|H6{Ivisk^8tq=}av*K7TE%$pEX@9g5eGG% zip3!WClMM%Q3~Tz6hkBg(>Op=7*9=+5Q`ubO|S%mK@5$ceCh~aNIp-NKnVm9%#u-U z+OX^EBF^K9)z*=C^`D+Mhil(g*z>pQ*M*lRUY{$P=oPw%V2}k_ny))WgA~b75C&oh ziNFLxK>&-2aT*aLBtswoL9!6Q04Rczd8p%e0X(~3-?l_&uKAs9h1Tuku)9lqOK(AMB>A)#U0!y_W2qGMv?;u8|T6U>tV zN&|j4XJQf${GmGV&4gag(PWzvvol%}?qt5&Z0pm zba&N+L%p~D82#6*E5=m^bpi$&ww(FV7Ezfa3SkpL!7EvK)&A#K9m*2k`v!B>#vMt$ zcUyPtFF5}pZ%KE?qC@KgcByEHB4R05Hc_B0yI}b_`j(IxY?AJ1GV1L<^wey0!|v!;aVx!q8iQo%ad|=F&SBXcn_+){V#qBp&W4~?k4GrCMq0>5zwKpGL5xdIHjpbt<1g5gsJ#UX> zn@AsLj+2rmKigAM1=dGBb?6!a5v~@gL!9&6)85&IgKWtA;#yQLWy?t>OI@Du?53N`GeI(ad;}g}S z(K}nOTzliip#g8>g{vMpuQ;K9+Mp*@k|l2RP4gelym#7g(95Dne5hzbxJEK#UtA#9 z(v#=kx0!VvD0KWKDCx)7dAWrprdk2xr1j{6aA5D^)&yS5jE&PwuH~isNpxR>cK&i%3G7G=cA6z;Zac6eSL*?71ArJNs-LDwuwanOA73EqE)vF#Gn?t;H zI9?E+^SS(1PFF~hVb#03wCk?bsX(3SVx?8;S4VW3PnB$NK9D@2zr%skV0>QR(N}YS z)puN)q2eN$x%KMG#heOy6=!#PS#5pKkiAuc z@<1Pu*u2fI^k8{I@3Me+&(a2;t=DQ66dRQAg_*H8&zEblHF{gH*3vE0;De3vn%LX> z#|NY>wqrhieY>;I&TD>m!>`eGzDW4yo@i6Y(eY@*)N2Q}6{Jiq+wj18wMYLiA+x3i zW~Sz?{GTSB&Cj<~-G&VYibC`&EjpH-==wQHH!SzFbmK9l#&F5gU4hQ`BEC%h%EXT` z_v>FD;T~A@_{1}$*pM_?`LB}fsezfPyU&$t$wMz2tuesUmmbbKzt(ueqImcA#PA?E z#Nd<7S1+DdWoQqx!m&o>mx*Txi+&*3N*(hy#Z9Y$9AD7W zZkYW}Nk1*YroVT2p3P?^%cdx{TIHfgC8oNzzvfDd@*K(Z0vVO#owqpoy0 z73ar)ywjHZlb83rLLWP0&5}*a+aL&nnJ+qPn!e%fRS(Y_L2>?R-!F<%seYcG zchsgrS!2q4r#6h195M2obI?QE+|0uP+o3+~=PP#{JjI39g#u~q{e3-Z-d8{Es@C;X z#1H#89o@XB-@3BITI3eABz4}mXV<+6&CXHeQz{&Z`~nXe<7!Urp@ z9Ixf(P+d-Kb$UBnUidnW*;d?Aeq`16^ixO?*f^TEZ#Yp$v@{{KT_?AG_)qsTHKD{_ zFk22*Tep8l#fKX3?{pX6{0{@pZ8oAg?=-!iSRbEV^CqKMOVxtiyC_rhv)S7RdR;n~ z8ip2R { - 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 }) diff --git a/test/fixtures/test-keys-path.js b/test/fixtures/test-keys-path.js new file mode 100644 index 0000000..0ac277f --- /dev/null +++ b/test/fixtures/test-keys-path.js @@ -0,0 +1 @@ +export default './test/fixtures/newtestkeys2' \ No newline at end of file diff --git a/test/identities/identities.test.js b/test/identities/identities.test.js index 763fa94..2af63ec 100644 --- a/test/identities/identities.test.js +++ b/test/identities/identities.test.js @@ -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 () => { diff --git a/test/key-store.test.js b/test/key-store.test.js index 2e6ce8f..eab27f1 100644 --- a/test/key-store.test.js +++ b/test/key-store.test.js @@ -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) }) diff --git a/test/oplog/crdt.test.js b/test/oplog/crdt.test.js index cac935c..93b6eac 100644 --- a/test/oplog/crdt.test.js +++ b/test/oplog/crdt.test.js @@ -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 () => { diff --git a/test/oplog/entry.test.js b/test/oplog/entry.test.js index a204737..35035e2 100644 --- a/test/oplog/entry.test.js +++ b/test/oplog/entry.test.js @@ -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,9 +30,8 @@ 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' }) }) diff --git a/test/oplog/heads.test.js b/test/oplog/heads.test.js index e1222f6..0286ce3 100644 --- a/test/oplog/heads.test.js +++ b/test/oplog/heads.test.js @@ -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 }) diff --git a/test/oplog/join-concurrent.test.js b/test/oplog/join-concurrent.test.js index e95997c..f27d8cf 100644 --- a/test/oplog/join-concurrent.test.js +++ b/test/oplog/join-concurrent.test.js @@ -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 () => { diff --git a/test/oplog/log.test.js b/test/oplog/log.test.js index 80fe57b..f49681e 100644 --- a/test/oplog/log.test.js +++ b/test/oplog/log.test.js @@ -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() diff --git a/test/oplog/references.test.js b/test/oplog/references.test.js index ca2734f..8b3f1be 100644 --- a/test/oplog/references.test.js +++ b/test/oplog/references.test.js @@ -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() diff --git a/test/storage.spec.js b/test/storage.spec.js index 691b0b5..8b2c21e 100644 --- a/test/storage.spec.js +++ b/test/storage.spec.js @@ -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') })