Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSockets integration #73

Closed
travisapple opened this issue Oct 28, 2024 · 3 comments
Closed

WebSockets integration #73

travisapple opened this issue Oct 28, 2024 · 3 comments

Comments

@travisapple
Copy link

First off, this project is fantastic, thank you!

Feature Request:

I'm trying to integrate this into a websockets project that has no form tag. The challenge comes in via websockets, the user solves the challenge and the result is sent out via websockets to a server that verifies it.

This code works:

const altcha = document.createElement('altcha-widget')
altcha.setAttribute('challengejson', JSON.stringify( challenge ))
altcha.setAttribute('auto', 'onload')
altcha.style.display = 'none'

const c = document.querySelector('#container')
c.append(altcha)

await import('altcha.min.js')

altcha.addEventListener('statechange', (ev) => {
	if (ev.detail.state == 'verified') {
		console.log('altcha done')
	}
})

but it's pretty clunky using the dom when I don't need to. Is it possible to have something like this:

const result = await altcha.solve(challenge)

or maybe with a callback?

altcha.solve(challenge, (result)=>{
console.log('altcha done')
})

@ovx
Copy link
Contributor

ovx commented Oct 29, 2024

Hi, for this purpose you can use the solveChallenge function from the altcha-lib package (https://github.com/altcha-org/altcha-lib?tab=readme-ov-file#solvechallengechallenge-salt-algorithm-max-start) which does not require DOM.

@travisapple
Copy link
Author

travisapple commented Nov 1, 2024

Hey thanks OVX.

The front end widget doesn't have that function. solveChallenge() is only available on the server.

@ovx
Copy link
Contributor

ovx commented Nov 6, 2024

The package altcha-lib works also in the browsers, you have to install it instead of the widget.

@ovx ovx closed this as completed Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants