@prosopo/server
v2.2.3
Published
NodeJS package for server side communication with the prosopo captcha client
Downloads
681
Readme
@prosopo/server
npm package to make verifying Procaptcha soltions easy.
Installation
You can install this library with:
npm install @prosopo/server --save
Basic Usage
Simply import the ProsopoServer
class and instantiate it with your Procaptcha API key.
import { ApiParams, ProcaptchaResponse } from '@prosopo/types'
import { ProsopoServer } from '@prosopo/server'
async function getProsopoServer() {
const config = getProsopoConfig()
const pairType = (process.env.PAIR_TYPE as KeypairType) || ('sr25519' as KeypairType)
const ss58Format = parseInt(process.env.SS58_FORMAT || '') || 42
const pair = await getPair(pairType, ss58Format, process.env.PROSOPO_SITE_PRIVATE_KEY)
const prosopoServer = new ProsopoServer(pair, config)
}
async function protectedFunction(server: ProsopoServer, payload: ProcaptchaResponse) {
if (await server.isVerified(payload[ApiParams.procaptchaResponse])) {
// perform CAPTCHA protected action
}
}
const payload = getPayloadFromRequest() // your request payload
getProsopoServer().then((server) => {
protectedFunction(server, payload).then(() => {
// ...
})
})
The full example can be seen here.