open-index/open-npm huggingface dataset:
npm package: @prosopo/client-example-server
Description: Backend for client-example
Author: PROSOPO LIMITED
Latest version: 2.7.56

# client-example-server

This example server implements signup, login and authorisation methods for a typical node backend application. The code
is based
on [an article written by Agustin Fernandez](https://www.asapdevelopers.com/build-a-react-native-login-app-with-node-js-backend/)
and is adapted to use a Mongo In-Memory Database. This backend server integrates with the client-example React app.

## Quickstart

### Test Your Site Key and Secret Key

#### 1. Build & Deploy

From the root of this repository, run the following commands:

```bash
cp demos/client-example-server/env.production demos/client-example-server/.env.production && \
npm i && \
npm run start:server
```

Make sure you replace the following placeholders in the `.env.production` file with your own site key and secret key.
You can obtain these by logging into the [Prosopo portal](https://portal.prosopo.io).

```typescript
PROSOPO_SITE_KEY=<YOUR SITE KEY HERE>
PROSOPO_SITE_PRIVATE_KEY=<YOUR SECRET KEY HERE>
```

Run this example API in conjunction with
the [client-example](https://github.com/prosopo/captcha/tree/main/demos/client-example) React app.

## 🚧 Developing the Client Example Server

You can run in development mode to make changes to the client-example-server by following these instructions:

### Build & Deploy

From the root of this repository, run the following commands:

```bash
cp demos/client-example-server/env.development demos/client-example-server/.env.development && \
cp dev/scripts/env.development dev/scripts/.env.development && \
docker compose --file ./docker/docker-compose.development.yml up -d && \
npm i && \
npm run build:all && \
npm run setup:all && \
npm run start:server
```

### Use the API

The server should now be running at localhost:9228. You can customise this in the `.env.development` file. Run this
example API in conjunction with the [client-example](https://github.com/prosopo/captcha/tree/main/demos/client-example)
React app.
npm package: @prosopo/datasets
Description: Datasets for use with providers
Author: PROSOPO LIMITED
Latest version: 3.0.55

# datasets

Datasets for use with providers

## STL10

Workbook adapted from [kaggle notebook](https://www.kaggle.com/code/pratt3000/generate-stl10/notebook) to generate 10,000 unique CAPTCHA.

Download the [binary files here](http://ai.stanford.edu/~acoates/stl10/stl10_binary.tar.gz).
npm package: @prosopo/keyring
Description: Keypair generator for Prosopo
Author: Prosopo Limited
Latest version: 2.9.0

This is a selective clone
of [keyring](https://github.com/polkadot-js/common/tree/25fe5f4e27d6dfe0a26082925a49207f2bfcd9fd/packages/keyring)
from the Polkadot JS repository at `25fe5f4e27d6dfe0a26082925a49207f2bfcd9fd`. Modifications have been made as follows:

- tests switched to vitest
- package name changed to @prosopo/util-crypto
- WASM dropped and replaced with JS implementation of sr25519 from @scure/sr25519
- other account types (`ecdsa`, `ed25519`, `ethereum`) dropped
npm package: @prosopo/load-balancer
Description: Provider load balancer
Author: Prosopo Limited
Latest version: 2.8.17

# @prosopo/load-balancer

Provider load balancer for Procaptcha

## Provider Selection Config

Each provider in the json has the following properties:

```typescript
{
  address: string;      // Provider account address
  url: string;          // Provider API endpoint
  datasetId: string;    // Dataset identifier
  weight?: number;      // Optional weight (1-100, defaults to 1)
}
```

### Weight Field

The `weight` field controls how often a provider is selected:

- **Range**: 1-100 (values outside this range are automatically coerced)
- **Default**: 1 (if not specified)
- **Type**: Integer (decimal values are rounded)
- **Effect**: Higher weight = more traffic

#### Examples

```json
{
  "provider1": {
    "address": "...",
    "url": "https://provider1.example.com",
    "datasetId": "...",
    "weight": 1
  },
  "provider2": {
    "address": "...",
    "url": "https://provider2.example.com",
    "datasetId": "...",
    "weight": 3
  }
}
```

In this example:
- Total weight = 4
- Provider 1 receives ~25% of traffic
- Provider 2 receives ~75% of traffic
npm package: @prosopo/procaptcha
Description: Contains interfaces for accessing the Prosopo [protocol](https://github.com/prosopo/protocol/) contract, Prosopo [provider](https://github.com/prosopo/provider) API and the captcha client state via the `ProsopoCaptchaClient` , `ProsopoCaptchaApi` and `Pro
Author: PROSOPO LIMITED
Latest version: 2.9.27

# Procaptcha

Contains interfaces for accessing the Prosopo [protocol](https://github.com/prosopo/protocol/) contract,
Prosopo [provider](https://github.com/prosopo/provider) API and the captcha client state via the `ProsopoCaptchaClient`
, `ProsopoCaptchaApi` and `ProsopoCaptchaStateClient` classes.

## Prerequisites

The Dapp smart contract account must
be [registered](https://github.com/prosopo/protocol/blob/5cb282a911522bfbf29d34d1830badee3eecec83/contracts/lib.rs#L698-L737)
in the Prosopo [protocol](https://github.com/prosopo/protocol/) contract in order to interact with the Prosopo protocol.
You can complete Dapp registration by navigating to [polkadot-js apps](https://polkadot.js.org/apps/) and using the
contracts page.

![contracts-page.png](assets/contracts-page.png)

## Usage

This repository can be imported into any JavaScript framework and used to create a CAPTCHA User Interface. See, for
example, the [procaptcha-react](https://github.com/prosopo/procaptcha-react) repository.
npm package: @prosopo/procaptcha-wrapper
Description: It's a core package for all the Procaptcha framework integrations.
Author: PROSOPO LIMITED
Latest version: 2.6.46

# Procaptcha Wrapper

## 1. About the package

It's a core package for all the Procaptcha framework integrations.

> Note: You shouldn't use this package directly as long as the target framework integration is available.

## 2. Configuration options

The package supports all the [Procaptcha options](https://docs.prosopo.io/en/basics/client-side-rendering/).

## 3. Direct usage

This package is written in vanilla JS, so in case there is no integration for your framework yet, you can use the package
directly:

```typescript
import { type ProcaptchaRenderOptions, renderProcaptcha} from "@prosopo/procaptcha-wrapper";

const container = document.querySelector('#your-element');

const procaptchaOptions: ProcaptchaRenderOptions = {
    siteKey: "your-site-key",
};

renderProcaptcha(container, procaptchaOptions);
```
npm package: @prosopo/protocol-dev
Description: Dev tools for working with prosopo contracts
Author: Prosopo Limited
Latest version: 0.2.17

# CLI for managing the contract / crates

Commands:
- `build`: build the contracts to /target directory. Unless `--package [pkg_name]` is specified, all contracts will be built. Add `--docker` to run from the parity contracts-ci image. Add `--package [pkg_name]` to target a specific crate/contract.
- `test`: test all crates and contracts. Add `--docker` to run from the parity contracts-ci image. Add `--package [pkg_name]` to target a specific crate/contract.
- `fmt`: format all crates and contracts. Add `--docker` to run from the parity contracts-ci image. Add `--package [pkg_name]` to target a specific crate/contract.
- `clippy`: run clippy on all crates and contracts. Add `--fix` to have clippy auto-fix any issues it detects. Add `--docker` to run from the parity contracts-ci image. Add `--package [pkg_name]` to target a specific crate/contract.
- `chown`: take ownership of the /target and /contracts directories, as running commands in docker mode may have changed them to belong to the root user (this is an issue with parity's contract-ci image - nothing we can do about it right now)
- `expand`: expand a contract. This takes any macro calls/attributes and unwraps them using `cargo-expand`. This is helpful for seeing the output of a macro. Add `--package [pkg_name]` to target a specific crate/contract.
- `metadata`: generate the metadata for a contract. Sometimes `cargo` gets stuck on this, so it's helpful to be able to run it directly to observe the error. Add `--package [pkg_name]` to target a specific crate/contract.

Run the above commands using `npm run cli -- <command> <args>`. E.g. to build the captcha contract in release mode, run
```
npm run cli -- build --package captcha --release
```
npm package: @prosopo/react-procaptcha-integration-demo
Description: It's a demo React application that showcases usage of `@prosopo/react-procaptcha-wrapper`, the React Procaptcha integration component.
Author: PROSOPO LIMITED
Latest version: 1.1.44

# React Procaptcha Integration demo

It's a demo React application that showcases usage of `@prosopo/react-procaptcha-wrapper`, the React Procaptcha
integration component.
npm package: @prosopo/react-procaptcha-wrapper
Description: A React component that provides seamless integration of [Procaptcha](https://prosopo.io/) into any React project.
Author: PROSOPO LIMITED
Latest version: 1.1.44

# React Procaptcha Wrapper

A React component that provides seamless integration of [Procaptcha](https://prosopo.io/) into any React project.

Refer to the [Procaptcha Docs](https://docs.prosopo.io/en/) to see an example of usage.
npm package: @prosopo/server
Description: NodeJS package for server side communication with the prosopo captcha client
Author: PROSOPO LIMITED
Latest version: 2.9.52

# @prosopo/server

npm package to make verifying Procaptcha soltions easy.

## Installation

You can install this library with:

```bash
npm install @prosopo/server --save
```

## Basic Usage

Simply import the `ProsopoServer` class and instantiate it with your Procaptcha API key.

```typescript
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](https://github.com/prosopo/captcha/blob/main/demos/client-example-server/src/app.ts).
npm package: @prosopo/svelte-procaptcha-integration-demo
Description: It's a demo Svelte application that showcases usage of `@prosopo/svelte-procaptcha-wrapper`, the Svelte Procaptcha integration component.
Author: PROSOPO LIMITED
Latest version: 1.1.44

# Svelte Procaptcha Integration demo

It's a demo Svelte application that showcases usage of `@prosopo/svelte-procaptcha-wrapper`, the Svelte Procaptcha
integration component.
npm package: @prosopo/svelte-procaptcha-wrapper
Description: A Svelte component that provides seamless integration of [Procaptcha](https://prosopo.io/) into any Svelte project.
Author: PROSOPO LIMITED
Latest version: 1.1.44

# Svelte Procaptcha Wrapper

## 1. About the package

A Svelte component that provides seamless integration of [Procaptcha](https://prosopo.io/) into any Svelte project.

Refer to the [Procaptcha Docs](https://docs.prosopo.io/en/) to see an example of usage.
npm package: @prosopo/ts-brand
Description: Brand your TypeScript types
Author: Prosopo Limited
Latest version: 3.0.30

# Brand your TypeScript types

See our [tutorial](https://prosopo.io/articles/typescript-branding/) for more info on what branding is and why you'd want to use it.

## Nominal types example

```ts
type A = {
    x: number
    y: boolean
    z: string
}

type B = {
    x: number
    y: boolean
    z: string
}
```

Type `A` and `B` are equal in the eyes of TypeScript.

```ts
const fn = (a: A) => {
    console.log('do something with A')
}

const obj: B = {
    x: 1,
    y: true,
    z: 'hello',
}

fn(obj) // absolutely fine, even though fn accepts types of A and obj is of type B!
```

Let's brand `A`

```ts
type ABranded = Brand<A, 'A'> // {
//     x: number;
//     y: boolean;
//     z: string;
// } & {
//     [brandKey]: "A";
// }
```

```ts
const fn = (a: ABranded) => {
    console.log('do something with A')
}

const obj: B = {
    x: 1,
    y: true,
    z: 'hello',
}

fn(obj) // Now this doesn't work, cannot accept any type other than ABranded!
```

Now the function only accepts a set type.

## Mapped type example

Using `ABranded` from before, we can do conditional typing.

```ts
type IsA<T> = T extends ABranded ? true : false

type x = IsA<ABranded> // true
type y = IsA<B> // false
```

Obviously this is a simple example, but branding enables conditional typing. This would be impossible using regular types in TypeScript, because type `B` is seen as equal to type `A`. [Read our blog post for a more detailed explanation](https://prosopo.io/articles/typescript-mapped-type-magic/).

## Classes & Instances

You can brand instances of a class or the class itself (which will produce branded instances).

```ts
class Dog {
    constructor(public name: string) {}
}

const DogBranded = brandClass(Dog, 'Dog') // adds the 'Dog' brand, making a new type

const dog = new DogBranded('Spot') // ok, of type DogBranded
```

Conditional typing can now be done using classes.

Or to brand an instance:

```ts
const dogBranded = brand(new Dog(), 'Dog') of type Dog & { [brandKey]: 'Dog' }
```

## Unbranding

Simply do the inverse to get back to the original type.

```ts
const DogUnbranded = unbrandClass(DogBranded) // same as the Dog class

const dog = new DogUnbranded('Spot') // ok, of type Dog
```

Or to unbrand an instance:

```ts
const dogUnbranded = unbrand(dog) // of type Dog
```

## Get brand

Given a unknown branded value

```ts
const b = getBrand(dog) // b is of type 'Dog'
```

No brand set:

```ts
const b = getBrand(someValue) // b is of type '' - i.e. no brand
```

## Important note

Branding is type only, so only available at compile time! This means using things like `getBrand()` will give you the brand as a type, not as a runtime variable!
npm package: @prosopo/tx
Description: Helper functions for working with transactions in Polkadot.
Author: PROSOPO LIMITED
Latest version: 2.2.3

# @prosopo/tx

Helper functions for working with transactions in Polkadot.

## Tx Queue

The `TxQueue` class is a simple queue that can be used to manage transactions in a Polkadot network. It is designed to
be used with the `@polkadot/api` package.