update secret-stack to 8.0

This commit is contained in:
Andre Staltz 2023-12-29 13:00:45 +02:00
parent d7a5c2694f
commit 0cd2a56fc8
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
5 changed files with 42 additions and 31 deletions

View File

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

View File

@ -14,8 +14,8 @@ function getAccount(iter) {
}
test('sync an account tangle', async (t) => {
const alice = createPeer({ name: 'alice', keypair: aliceKeypair })
const bob = createPeer({ name: 'bob', keypair: bobKeys })
const alice = createPeer({ name: 'alice', global: { keypair: aliceKeypair } })
const bob = createPeer({ name: 'bob', global: { keypair: bobKeys } })
await alice.db.loaded()
await bob.db.loaded()
@ -51,7 +51,6 @@ test('sync an account tangle', async (t) => {
"bob doesn't have alice's account tangle"
)
// start() on purpose before connect, to test whether this also works
bob.sync.start()
const remoteAlice = await p(bob.connect)(alice.getAddress())

View File

@ -17,7 +17,9 @@ test('sync goal=dict with ghostSpan=2', async (t) => {
const SPAN = 5
const alice = createPeer({
name: 'alice',
global: {
keypair: aliceKeypair,
},
dict: { ghostSpan: SPAN },
})
const bob = createPeer({ name: 'bob' })
@ -132,11 +134,7 @@ test('sync goal=dict with ghostSpan=2', async (t) => {
.map((msg) => msg.data?.update)
.filter((x) => !!x)
.map((x) => x.age ?? x.name ?? x.gender)
assert.deepEqual(
arr,
[25, 'ALICE', 'w'],
'alice has age+name+gender dict'
)
assert.deepEqual(arr, [25, 'ALICE', 'w'], 'alice has age+name+gender dict')
}
assert.deepEqual(alice.db.ghosts.get(moot.id), [rec2.id])

View File

@ -25,7 +25,9 @@ test('sync goal=set with ghostSpan=2', async (t) => {
const SPAN = 5
const alice = createPeer({
name: 'alice',
global: {
keypair: aliceKeypair,
},
set: { ghostSpan: SPAN },
})
const bob = createPeer({ name: 'bob' })

View File

@ -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-sync-${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-sync-${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'))
@ -25,7 +34,9 @@ function createPeer(opts) {
.use(require('ssb-box'))
.use(require('../lib'))
.call(null, {
caps,
shse: { caps },
...config,
global: {
connections: {
incoming: {
net: [{ scope: 'device', transform: 'shse', port: null }],
@ -34,7 +45,8 @@ function createPeer(opts) {
net: [{ transform: 'shse' }],
},
},
...opts,
...config.global,
},
})
}