diff --git a/libs/waku-utils/examples/demo.ts b/libs/waku-utils/examples/demo.ts new file mode 100644 index 00000000..6e93f86e --- /dev/null +++ b/libs/waku-utils/examples/demo.ts @@ -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() diff --git a/libs/waku-utils/tsconfig.lib.json b/libs/waku-utils/tsconfig.lib.json index 4ff19243..eeeea43e 100644 --- a/libs/waku-utils/tsconfig.lib.json +++ b/libs/waku-utils/tsconfig.lib.json @@ -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/**/*"] }