This commit is contained in:
Raven Scott
2026-05-20 22:56:32 -04:00
parent b8c335adee
commit dd384eb944
321 changed files with 7484 additions and 3793 deletions
@@ -1,26 +1,39 @@
require('bare-process/global')
const test = require('brittle')
const b4a = require('b4a')
const { HyperP2PEncryptedTopic, PROTOCOL } = require('../index.js')
test('exports', (t) => {
t.ok(HyperP2PEncryptedTopic)
t.ok(PROTOCOL)
t.is(PROTOCOL, 'encrypted-topic/v1')
})
test('basic operation', async (t) => {
test('encrypt decrypt roundtrip', async (t) => {
const m = new HyperP2PEncryptedTopic()
m.put('k', 1); t.is(m.get('k'), 1)
m.registerTopic('secret', 'hint-abc')
const plain = b4a.from('hello peers')
const cipher = m.encryptPayload('secret', plain)
const out = m.decryptPayload('secret', cipher)
t.alike(out, plain)
await m.close()
})
test('unregistered topic throws', async (t) => {
const m = new HyperP2PEncryptedTopic()
try { m.encryptPayload('nope', 'x') } catch (e) { t.ok(e) }
await m.close()
})
test('validation', async (t) => {
const m = new HyperP2PEncryptedTopic()
try { m.put(null, 1) } catch (e) { t.ok(e) }
try { m.registerTopic(null, 'h') } catch (e) { t.ok(e) }
await m.close()
})
test('getStats', async (t) => {
const m = new HyperP2PEncryptedTopic()
t.ok(m.getStats().protocol)
m.registerTopic('t', 'h')
m.encryptPayload('t', 'a')
t.is(m.getStats().encrypted, 1)
await m.close()
})