From 231976998fb1c86155db1eab26cd4f2d74ae2d5f Mon Sep 17 00:00:00 2001 From: Hayden Young Date: Mon, 26 May 2025 10:35:47 +0200 Subject: [PATCH] test: Enc/dec using simple encryption module. --- package-lock.json | 19 +++++++++++++++++++ package.json | 1 + test/fixtures/encryption/custom.js | 27 --------------------------- test/orbitdb-encryption.test.js | 10 +++++----- 4 files changed, 25 insertions(+), 32 deletions(-) delete mode 100644 test/fixtures/encryption/custom.js diff --git a/package-lock.json b/package-lock.json index f8687e9..c41a5ec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,7 @@ "devDependencies": { "@chainsafe/libp2p-gossipsub": "^14.1.0", "@libp2p/circuit-relay-v2": "^3.1.0", + "@orbitdb/simple-encryption": "github:orbitdb/simple-encryption", "blockstore-level": "^2.0.1", "c8": "^8.0.1", "cross-env": "^7.0.3", @@ -2758,6 +2759,24 @@ "node": ">= 8" } }, + "node_modules/@orbitdb/simple-encryption": { + "version": "0.0.1", + "resolved": "git+ssh://git@github.com/orbitdb/simple-encryption.git#1aef41220a24fdad067ccb34cb14456b68bbdaf5", + "dev": true, + "license": "MIT", + "dependencies": { + "multiformats": "^13.3.6" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@orbitdb/simple-encryption/node_modules/multiformats": { + "version": "13.3.6", + "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-13.3.6.tgz", + "integrity": "sha512-yakbt9cPYj8d3vi/8o/XWm61MrOILo7fsTL0qxNx6zS0Nso6K5JqqS2WV7vK/KSuDBvrW3KfCwAdAgarAgOmww==", + "dev": true + }, "node_modules/@peculiar/asn1-cms": { "version": "2.3.15", "resolved": "https://registry.npmjs.org/@peculiar/asn1-cms/-/asn1-cms-2.3.15.tgz", diff --git a/package.json b/package.json index cc419b7..e597211 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "devDependencies": { "@chainsafe/libp2p-gossipsub": "^14.1.0", "@libp2p/circuit-relay-v2": "^3.1.0", + "@orbitdb/simple-encryption": "github:orbitdb/simple-encryption", "blockstore-level": "^2.0.1", "c8": "^8.0.1", "cross-env": "^7.0.3", diff --git a/test/fixtures/encryption/custom.js b/test/fixtures/encryption/custom.js deleted file mode 100644 index 1dddd97..0000000 --- a/test/fixtures/encryption/custom.js +++ /dev/null @@ -1,27 +0,0 @@ -const CustomEncryption = async ({ fail } = {}) => { - fail = fail || false - - const key = 'encrypted' - const bufferedKey = new Uint8Array(Buffer.from(key)) - - const encrypt = (value) => { - return new Uint8Array([...bufferedKey, ...value]) - } - - const decrypt = (value) => { - const detectedBufferedKey = new Uint8Array(value.slice(0, bufferedKey.length)) - const rawValue = new Uint8Array(value.slice(bufferedKey.length)) - if (detectedBufferedKey.length == bufferedKey.length && !fail) { - return rawValue - } else { - throw new Exception('invalid encryption') - } - } - - return { - encrypt, - decrypt - } -} - -export default CustomEncryption diff --git a/test/orbitdb-encryption.test.js b/test/orbitdb-encryption.test.js index 1144a93..6c3d465 100644 --- a/test/orbitdb-encryption.test.js +++ b/test/orbitdb-encryption.test.js @@ -10,7 +10,7 @@ import * as Block from 'multiformats/block' import * as dagCbor from '@ipld/dag-cbor' import { sha256 } from 'multiformats/hashes/sha2' -import CustomEncryption from './fixtures/encryption/custom.js' +import SimpleEncryption from '@orbitdb/simple-encryption' const codec = dagCbor const hasher = sha256 @@ -36,8 +36,8 @@ describe('Encryption', function () { orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: path.join(dbPath, '1') }) orbitdb2 = await createOrbitDB({ ipfs: ipfs2, id: 'user2', directory: path.join(dbPath, '2') }) - replicationEncryption = await CustomEncryption() - dataEncryption = await CustomEncryption() + replicationEncryption = await SimpleEncryption({ password: 'hello' }) + dataEncryption = await SimpleEncryption({ password: 'world' }) }) after(async () => { @@ -218,7 +218,7 @@ describe('Encryption', function () { let hasError = false let error - const replicationEncryptionWithFailure = await CustomEncryption({ fail: true }) + const replicationEncryptionWithFailure = await SimpleEncryption({ password: 'goodbye' }) const encryption = { replication: replicationEncryption @@ -261,7 +261,7 @@ describe('Encryption', function () { let hasError = false let error - const dataEncryptionWithFailure = await CustomEncryption({ fail: true }) + const dataEncryptionWithFailure = await SimpleEncryption({ password: 'goodbye' }) const encryption = { data: dataEncryption