diff --git a/package.json b/package.json index 57a6275..e8a6c0c 100644 --- a/package.json +++ b/package.json @@ -34,8 +34,8 @@ "ppppp-caps": "github:staltz/ppppp-caps", "ppppp-keypair": "github:staltz/ppppp-keypair", "rimraf": "^4.4.0", - "secret-stack": "~7.1.1", - "secret-handshake-ext": "0.0.8", + "secret-stack": "~8.0.0", + "secret-handshake-ext": "0.0.10", "ssb-box": "^1.0.1", "typescript": "^5.1.3" }, diff --git a/test/index.test.js b/test/index.test.js index 6eca6d1..89911fd 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -17,8 +17,10 @@ let peer let aliceID test('setup', async (t) => { peer = createPeer({ - keypair: aliceKeypair, - db: { path: DIR }, + global: { + keypair: aliceKeypair, + path: DIR, + }, set: { ghostSpan: 40 }, }) diff --git a/test/util.js b/test/util.js index 9c4d2ef..ff47a08 100644 --- a/test/util.js +++ b/test/util.js @@ -1,20 +1,29 @@ -const os = require('node:os') -const path = require('node:path') +const OS = require('node:os') +const Path = require('node:path') const rimraf = require('rimraf') const caps = require('ppppp-caps') const Keypair = require('ppppp-keypair') -function createPeer(opts) { - if (opts.name) { - const tmp = os.tmpdir() - opts.db ??= {path: path.join(tmp, `ppppp-set-${opts.name}-${Date.now()}`)} - opts.keypair ??= Keypair.generate('ed25519', opts.name) - opts.name = undefined +function createPeer(config) { + if (config.name) { + const name = config.name + const tmp = OS.tmpdir() + config.global ??= {} + config.global.path ??= Path.join(tmp, `ppppp-set-${name}-${Date.now()}`) + config.global.keypair ??= Keypair.generate('ed25519', name) + delete config.name + } + if (!config.global) { + throw new Error('need config.global in createPeer()') + } + if (!config.global.path) { + throw new Error('need config.global.path in createPeer()') + } + if (!config.global.keypair) { + throw new Error('need config.global.keypair in createPeer()') } - if (!opts.db.path) throw new Error('need opts.db.path in createPeer()') - if (!opts.keypair) throw new Error('need opts.keypair in createPeer()') - rimraf.sync(opts.db.path) + rimraf.sync(config.global.path) return require('secret-stack/bare')() .use(require('secret-stack/plugins/net')) .use(require('secret-handshake-ext/secret-stack')) @@ -22,16 +31,19 @@ function createPeer(opts) { .use(require('ssb-box')) .use(require('../lib')) .call(null, { - caps, - connections: { - incoming: { - net: [{ scope: 'device', transform: 'shse', port: null }], - }, - outgoing: { - net: [{ transform: 'shse' }], + shse: { caps }, + ...config, + global: { + connections: { + incoming: { + net: [{ scope: 'device', transform: 'shse', port: null }], + }, + outgoing: { + net: [{ transform: 'shse' }], + }, }, + ...config.global, }, - ...opts, }) }