@prosopo/server
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

@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.

Readme

Keywords

none

Package Sidebar

Install

npm i @prosopo/server

Weekly Downloads

124

Version

1.0.2

License

Apache-2.0

Unpacked Size

34 kB

Total Files

18

Last publish

Collaborators

  • hughparry
  • goastler
  • christaylor