mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-10-07 22:57:07 +00:00
test: Enc/dec using simple encryption module.
This commit is contained in:
parent
b539877a39
commit
231976998f
19
package-lock.json
generated
19
package-lock.json
generated
@ -22,6 +22,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@chainsafe/libp2p-gossipsub": "^14.1.0",
|
"@chainsafe/libp2p-gossipsub": "^14.1.0",
|
||||||
"@libp2p/circuit-relay-v2": "^3.1.0",
|
"@libp2p/circuit-relay-v2": "^3.1.0",
|
||||||
|
"@orbitdb/simple-encryption": "github:orbitdb/simple-encryption",
|
||||||
"blockstore-level": "^2.0.1",
|
"blockstore-level": "^2.0.1",
|
||||||
"c8": "^8.0.1",
|
"c8": "^8.0.1",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
@ -2758,6 +2759,24 @@
|
|||||||
"node": ">= 8"
|
"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": {
|
"node_modules/@peculiar/asn1-cms": {
|
||||||
"version": "2.3.15",
|
"version": "2.3.15",
|
||||||
"resolved": "https://registry.npmjs.org/@peculiar/asn1-cms/-/asn1-cms-2.3.15.tgz",
|
"resolved": "https://registry.npmjs.org/@peculiar/asn1-cms/-/asn1-cms-2.3.15.tgz",
|
||||||
|
|||||||
@ -31,6 +31,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@chainsafe/libp2p-gossipsub": "^14.1.0",
|
"@chainsafe/libp2p-gossipsub": "^14.1.0",
|
||||||
"@libp2p/circuit-relay-v2": "^3.1.0",
|
"@libp2p/circuit-relay-v2": "^3.1.0",
|
||||||
|
"@orbitdb/simple-encryption": "github:orbitdb/simple-encryption",
|
||||||
"blockstore-level": "^2.0.1",
|
"blockstore-level": "^2.0.1",
|
||||||
"c8": "^8.0.1",
|
"c8": "^8.0.1",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
|
|||||||
27
test/fixtures/encryption/custom.js
vendored
27
test/fixtures/encryption/custom.js
vendored
@ -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
|
|
||||||
@ -10,7 +10,7 @@ import * as Block from 'multiformats/block'
|
|||||||
import * as dagCbor from '@ipld/dag-cbor'
|
import * as dagCbor from '@ipld/dag-cbor'
|
||||||
import { sha256 } from 'multiformats/hashes/sha2'
|
import { sha256 } from 'multiformats/hashes/sha2'
|
||||||
|
|
||||||
import CustomEncryption from './fixtures/encryption/custom.js'
|
import SimpleEncryption from '@orbitdb/simple-encryption'
|
||||||
|
|
||||||
const codec = dagCbor
|
const codec = dagCbor
|
||||||
const hasher = sha256
|
const hasher = sha256
|
||||||
@ -36,8 +36,8 @@ describe('Encryption', function () {
|
|||||||
orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: path.join(dbPath, '1') })
|
orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: path.join(dbPath, '1') })
|
||||||
orbitdb2 = await createOrbitDB({ ipfs: ipfs2, id: 'user2', directory: path.join(dbPath, '2') })
|
orbitdb2 = await createOrbitDB({ ipfs: ipfs2, id: 'user2', directory: path.join(dbPath, '2') })
|
||||||
|
|
||||||
replicationEncryption = await CustomEncryption()
|
replicationEncryption = await SimpleEncryption({ password: 'hello' })
|
||||||
dataEncryption = await CustomEncryption()
|
dataEncryption = await SimpleEncryption({ password: 'world' })
|
||||||
})
|
})
|
||||||
|
|
||||||
after(async () => {
|
after(async () => {
|
||||||
@ -218,7 +218,7 @@ describe('Encryption', function () {
|
|||||||
let hasError = false
|
let hasError = false
|
||||||
let error
|
let error
|
||||||
|
|
||||||
const replicationEncryptionWithFailure = await CustomEncryption({ fail: true })
|
const replicationEncryptionWithFailure = await SimpleEncryption({ password: 'goodbye' })
|
||||||
|
|
||||||
const encryption = {
|
const encryption = {
|
||||||
replication: replicationEncryption
|
replication: replicationEncryption
|
||||||
@ -261,7 +261,7 @@ describe('Encryption', function () {
|
|||||||
let hasError = false
|
let hasError = false
|
||||||
let error
|
let error
|
||||||
|
|
||||||
const dataEncryptionWithFailure = await CustomEncryption({ fail: true })
|
const dataEncryptionWithFailure = await SimpleEncryption({ password: 'goodbye' })
|
||||||
|
|
||||||
const encryption = {
|
const encryption = {
|
||||||
data: dataEncryption
|
data: dataEncryption
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user