feat(waku-utils): Add waku handshake demo

This commit is contained in:
Emil Ivanichkov 2024-01-29 19:18:01 +02:00 committed by Emil Ivanichkov
parent 9174fa5cc5
commit 9bec7e2ece
2 changed files with 43 additions and 2 deletions

View File

@ -0,0 +1,41 @@
import debug from 'debug'
import { writeFileSync } from 'fs'
import { Protocols, createLightNode, waitForRemotePeer } from '@waku/sdk'
import * as utils from '@waku/utils/bytes'
import { getPairingObject, proceedHandshake } from 'waku-utils/src/waku-utils'
import { NoiseSecureMessage } from '@waku/noise/dist/codec'
debug.enable('nimbus-gui:*')
const log = debug('nimbus-gui:waku:demo')
async function startNode() {
const node = await createLightNode({
defaultBootstrap: true,
})
await node.start()
await waitForRemotePeer(node, [Protocols.Filter, Protocols.LightPush])
const pairingObj = getPairingObject(node)
const pInfo = pairingObj.getPairingInfo()
writeFileSync(
process.env['QR_MESSAGE_PATH']!,
utils.bytesToHex(pInfo.qrMessageNameTag),
)
writeFileSync(process.env['QR_PATH']!, pInfo.qrCode)
const { decoder } = await proceedHandshake(pairingObj)
const callback = (wakuMessage: NoiseSecureMessage) => {
log('New message received. Payload:', wakuMessage.payload)
}
await node.filter.subscribe([decoder], callback)
log('Subscription created')
}
log('Starting Waku')
startNode()

View File

@ -1,8 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"rootDir": "src"
},
"include": ["src/**/*.ts"],
"exclude": ["vite.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
"exclude": ["vite.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts", "examples/**/*"]
}