Chat updates
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Proves chat `senderPk` must be the **Noise** `socket.publicKey` (32 B), not
|
||||
* `swarm.keyPair.publicKey` — the peer's `remotePublicKey` matches the other
|
||||
* side's `publicKey` on the same connection, not the DHT key pair.
|
||||
*/
|
||||
import Hyperswarm from 'hyperswarm'
|
||||
import b4a from 'b4a'
|
||||
import { topicKey } from 'bare-os-protocol/constants.js'
|
||||
|
||||
const topic = topicKey()
|
||||
const a = new Hyperswarm()
|
||||
const b = new Hyperswarm()
|
||||
|
||||
const aKey = a.keyPair.publicKey
|
||||
const bKey = b.keyPair.publicKey
|
||||
let aSock = null
|
||||
let bSock = null
|
||||
|
||||
a.on('connection', (s) => {
|
||||
aSock = s
|
||||
check()
|
||||
})
|
||||
b.on('connection', (s) => {
|
||||
bSock = s
|
||||
check()
|
||||
})
|
||||
|
||||
function check() {
|
||||
if (!aSock || !bSock) return
|
||||
const remoteB = b4a.equals(aSock.remotePublicKey, bKey)
|
||||
const remoteA = b4a.equals(bSock.remotePublicKey, aKey)
|
||||
console.log(
|
||||
'DHT keyPair.pub === peer remotePk ?',
|
||||
' A.remote vs B.dht:',
|
||||
remoteB,
|
||||
' B.remote vs A.dht:',
|
||||
remoteA
|
||||
)
|
||||
console.log(
|
||||
'Noise wire identity (correct for chat senderPk):'
|
||||
)
|
||||
console.log(
|
||||
' B.remotePk === A.socket.publicKey',
|
||||
b4a.equals(bSock.remotePublicKey, aSock.publicKey)
|
||||
)
|
||||
console.log(
|
||||
' A.remotePk === B.socket.publicKey',
|
||||
b4a.equals(aSock.remotePublicKey, bSock.publicKey)
|
||||
)
|
||||
}
|
||||
|
||||
b.join(topic)
|
||||
await new Promise((r) => setTimeout(r, 400))
|
||||
a.join(topic)
|
||||
|
||||
await new Promise((r) => setTimeout(r, 12000))
|
||||
|
||||
if (!aSock || !bSock) {
|
||||
console.error('FAIL: missing connection within timeout (NAT/firewall?)')
|
||||
process.exitCode = 1
|
||||
}
|
||||
|
||||
await a.destroy()
|
||||
await b.destroy()
|
||||
Reference in New Issue
Block a user