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",
"pretty-quick": "^3.1.3",
"rimraf": "^4.4.0",
"secret-handshake-ext": "^0.0.8",
"secret-stack": "~7.1.0",
"secret-handshake-ext": "0.0.11",
"secret-stack": "~8.0.0",
"ssb-box": "^1.0.1",
"typescript": "^5.1.3"
},

View File

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

View File

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

View File

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

View File

@ -4,17 +4,26 @@ const rimraf = require('rimraf')
const caps = require('ppppp-caps')
const Keypair = require('ppppp-keypair')
function createPeer(opts) {
if (opts.name) {
function createPeer(config) {
if (config.name) {
const name = config.name
const tmp = OS.tmpdir()
opts.db ??= {path: Path.join(tmp, `ppppp-gc-${opts.name}-${Date.now()}`)}
opts.keypair ??= Keypair.generate('ed25519', opts.name)
opts.name = undefined
config.global ??= {}
config.global.path ??= Path.join(tmp, `ppppp-gc-${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'))
@ -24,16 +33,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,
})
}