update to secret-stack 8.0

This commit is contained in:
Andre Staltz 2023-12-29 13:03:28 +02:00
parent 0a52530ab2
commit 04161ad9db
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
5 changed files with 33 additions and 27 deletions

View File

@ -39,8 +39,8 @@
"prettier": "^2.6.2", "prettier": "^2.6.2",
"pretty-quick": "^3.1.3", "pretty-quick": "^3.1.3",
"rimraf": "^4.4.0", "rimraf": "^4.4.0",
"secret-handshake-ext": "^0.0.8", "secret-handshake-ext": "0.0.11",
"secret-stack": "~7.1.0", "secret-stack": "~8.0.0",
"ssb-box": "^1.0.1", "ssb-box": "^1.0.1",
"typescript": "^5.1.3" "typescript": "^5.1.3"
}, },

View File

@ -8,9 +8,7 @@ function getTexts(msgs) {
} }
test('Feed decay', async (t) => { test('Feed decay', async (t) => {
const alice = createPeer({ const alice = createPeer({ name: 'alice' })
name: 'alice',
})
await alice.db.loaded() await alice.db.loaded()

View File

@ -8,9 +8,7 @@ function getTexts(msgs) {
} }
test('Feed holes', async (t) => { test('Feed holes', async (t) => {
const alice = createPeer({ const alice = createPeer({ name: 'alice' })
name: 'alice',
})
await alice.db.loaded() await alice.db.loaded()

View File

@ -12,9 +12,7 @@ function getTexts(msgs) {
} }
test('Orphan weave msgs', async (t) => { test('Orphan weave msgs', async (t) => {
const alice = createPeer({ const alice = createPeer({ name: 'alice' })
name: 'alice',
})
await alice.db.loaded() await alice.db.loaded()

View File

@ -4,17 +4,26 @@ const rimraf = require('rimraf')
const caps = require('ppppp-caps') const caps = require('ppppp-caps')
const Keypair = require('ppppp-keypair') const Keypair = require('ppppp-keypair')
function createPeer(opts) { function createPeer(config) {
if (opts.name) { if (config.name) {
const name = config.name
const tmp = OS.tmpdir() const tmp = OS.tmpdir()
opts.db ??= {path: Path.join(tmp, `ppppp-gc-${opts.name}-${Date.now()}`)} config.global ??= {}
opts.keypair ??= Keypair.generate('ed25519', opts.name) config.global.path ??= Path.join(tmp, `ppppp-gc-${name}-${Date.now()}`)
opts.name = undefined 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')() return require('secret-stack/bare')()
.use(require('secret-stack/plugins/net')) .use(require('secret-stack/plugins/net'))
.use(require('secret-handshake-ext/secret-stack')) .use(require('secret-handshake-ext/secret-stack'))
@ -24,7 +33,9 @@ function createPeer(opts) {
.use(require('ssb-box')) .use(require('ssb-box'))
.use(require('../lib')) .use(require('../lib'))
.call(null, { .call(null, {
caps, shse: { caps },
...config,
global: {
connections: { connections: {
incoming: { incoming: {
net: [{ scope: 'device', transform: 'shse', port: null }], net: [{ scope: 'device', transform: 'shse', port: null }],
@ -33,7 +44,8 @@ function createPeer(opts) {
net: [{ transform: 'shse' }], net: [{ transform: 'shse' }],
}, },
}, },
...opts, ...config.global,
},
}) })
} }