Wampy.js supports challenge response authentication. To use it you need to provide authid and onChallenge callback as wampy instance options. Also, Wampy.js supports wampcra authentication method with a little helper plugin "wampy-cra". Just add "wampy-cra" package and use provided methods as shown below.
'use strict';constWampy=require('wampy').Wampy;constwampyCra=require('wampy-cra');constw3cws=require('websocket').w3cwebsocket;/** * Manual authentication using signed message */wampy =newWampy('wss://wamp.router.url', { ws: w3cws,// just for example in node.js env realm:'realm1', authid:'joe', authmethods: ['wampcra'],onChallenge: (method, info) => {console.log('Requested challenge with ', method, info);returnwampyCra.signManual('joe secret key or password',info.challenge); }});/** * Promise-based manual authentication using signed message */wampy =newWampy('wss://wamp.router.url', { realm:'realm1', authid:'micky', authmethods: ['wampcra'],onChallenge: (method, info) => {returnnewPromise((resolve, reject) => {setTimeout(() => {console.log('Requested challenge with ', method, info);resolve(wampyCra.signManual('micky secret key or password',info.challenge)); },2000); }); }});/** * Manual authentication using salted key and pbkdf2 scheme */wampy =newWampy('wss://wamp.router.url', { realm:'realm1', authid:'peter', authmethods: ['wampcra'],onChallenge: (method, info) => {constiterations=100;constkeylen=16;constsalt='password salt for user peter';console.log('Requested challenge with ', method, info);returnwampyCra.signManual(wampyCra.deriveKey('peter secret key or password', salt, iterations, keylen),info.challenge); }});/** * Automatic CRA authentication */wampy =newWampy('wss://wamp.router.url', { realm:'realm1', authid:'patrik', authmethods: ['wampcra'], onChallenge:wampyCra.sign('patrik secret key or password')});