Witness Chain
  • Introduction to Witness Chain
  • Infinity Watch
    • Proof of Location (Mainnet)
      • Introduction
      • Process flow
      • Architecture
      • Run a watchtower!
        • For Partner node runners
          • Running on Akash Cloud
          • Running on SuperNoderz
        • EigenLayer operators
          • Running a PoL Watchtower
          • Witness Chain AVS opt-in guide
        • At-home watchtowers
        • For DePIN/Validator Node provider
      • Demos
      • PoL Research
    • APIs
      • Campaign APIs
        • Key Terminologies
        • Authentication
        • Create Campaign
        • Edit campaign
        • Get Photo feed from campaign
        • Get Campaigns
      • Challenge APIs
        • Overview
        • Getting Started
  • Resources
    • Blogs
      • How Proof of Location Works
      • Redefining Geolocation Compliance: Witness Chain & Predicate
    • 🗞️Research
    • 🎙️Talks and Podcasts
    • 🤝Community
    • ⚖️Smart Contracts
    • File a bug
  • Archive
    • Introduction
    • Proof of Diligence Watchtower Protocol
      • How it works
      • Diligence Watchtower Roadmap
      • Watchtower Architecture
      • Chains watched
      • Smart Contracts
      • Quick Links
      • FAQs
    • For the node operators
      • Node requirements
      • Watchtower setup
        • [ARCHIVE] Mainnet Setup
          • L2 Archive Node Setup guide
        • Holesky Setup
          • L2 Archive Node Setup guide
        • Migration from archive to full node
      • Monitoring
    • Research
    • Keys Management
    • Proof of Bandwidth
      • Introduction
      • Architecture
      • For the node operators
        • Running a PoB Challenger Client
        • Running a PoB Prover Client
      • Demos
      • Research
    • 🤝Watchtower Protocol (Architecture v1)
      • 🗼How it works
      • 📅Watchtower Roadmap
      • 🏦Watchtower Architecture
      • 🔗Chains supported
Powered by GitBook
On this page
  1. Infinity Watch
  2. APIs
  3. Challenge APIs

Getting Started

PreviousOverviewNextBlogs

Last updated 6 months ago

Step 1: Pre-login and login

The pre-login and login APIs are crucial for the security and functionality of the Proof of Bandwidth or Proof of Location system. The APIs handles initial authentication steps, like generating session tokens and validating access. These APIs are foundational for safeguarding the prover's information and controlling system access, ensuring only authenticated users can interact with critical resources

Start the process by performing a pre-login and login request

Note: The {proof_type} parameter is crucial in all API requests and must be set to one of the following values:

  • pol (Proof of Location)

  • pob (Proof of Bandwidth)

Be sure to specify the appropriate value based on the context of your proof request.

Pre-login

Login

After the result is obtained, the /login api needs to be invoked

Step 2: Submit an on-chain Challenge Request

Refer to the following chain parameters to trigger a on-chain submitRequest

Parameters
Values

Chain ID

1237146866

Chain Kind

Polygon CDK (Validium)

Chain RPC

Chain Block Explorer

Contract Address Proxy to interact to initiate a on-chain challenge

Function to invoke

submitRequest

Parameters to pass to submitRequest - timeout - attributeIDs - challengeInfo

Contract ABI

Step 3: Trigger a Challenge with the Witness Chain Broker

Pass the challenge-id obtained in the previous step to the challenge-request-dcl API

Step 4: Monitor the status of the Challenge to obtain the results

One can monitor the status of the challenge to obtain the results using the challenge-status-dcl API

For PoB, For PoL,

We also have a written in Python, to trigger a PoL or a PoB challenge.

sample script
https://blue-orangutan-rpc.eu-north-2.gateway.fm/
https://blue-orangutan-blockscout.eu-north-2.gateway.fm/txs
0x8A02C91373929a4764F015309B072DC9C9Fabc49
https://github.com/witnesschain-com/pox-scheduler/blob/28b305c1faad39c47ae90e159303bc68695c09a1/src/run_challenge.py#L43
https://github.com/witnesschain-com/pox-scheduler/blob/28b305c1faad39c47ae90e159303bc68695c09a1/src/run_challenge.py#L96
https://blue-orangutan-blockscout.eu-north-2.gateway.fm/address/0x39B42E1CA5F34E989Df957f4D391996266a460bB?tab=contract
post

This API is to be called before logging in.

It will return a 'message' that has to be signed and sent to '/login' API.

This will also create a cookie;

hence the '/login' API must be called in a session.
Authorizations
Path parameters
proof_typestringRequired
Body
publicKeystringRequired

The key used for login
NOTE: when using 'ethereum' the 'publicKey = Address'
keyTypestring · enumRequired

The key-type of publicKey.

As of now these are supported keyTypes:
	1. solana
	2. ethereum
Possible values:
rolestring · enumRequired

The role the user intends to play after login:

	1. prover
		User who wants to prove what it offers to the network.

		Example: 'bandwidth', 'latency', 'disk', 'cpu' etc.

	2. challenger
		User who wants to challenge a 'prover'
		and earn rewards.

	3. payer
		An abstract entity/user who pays
		and requests for a challenge.

		A payer could be:
		the 'prover' itself, other users, or the blockchain.
Possible values:
projectNamestringOptional

If the user is also part of another blockchain project/app,

then the project-name/app-name can be provided here.

	e.g. "filecoin", "filecoin-station", "oort", etc.
projectPublicKeystringOptional

publicKey of the user associated with the

'projectName' blockchain project/app.
Responses
200
200 response
application/json
400
400 response
application/json
post
POST //proof/v1/{proof_type}/pre-login HTTP/1.1
Host: api.witnesschain.com
Cookie: YOUR_API_KEY
Content-Type: application/json
Accept: */*
Content-Length: 285

{
  "publicKey": "text",
  "walletPublicKey": {
    "solana": "text",
    "ethereum": "text"
  },
  "keyType": "ethereum",
  "role": "prover",
  "projectName": "text",
  "projectPublicKey": "text",
  "claims": {
    "{claim-parameter-1}": "text",
    "{claim-parameter-2}": "text",
    "{claim-parameter-3}": "text",
    "{claim-parameter-N}": "text"
  }
}
{
  "result": {
    "message": "text"
  }
}
post

This API logs in the user.

The user should send the 'message' that was received during the '/pre-login';

and must sign the 'message' using privateKey.

And send it in the 'signature' field.
Authorizations
Path parameters
proof_typestringRequired
Header parameters
CookiestringRequired

The cookies that were received after calling '/pre-login' API.
Body
signaturestringRequired

The signature afer signing the 'message' with the 'privateKey'.

The signature can be created using MetaMask/Phantom wallet.

These signatures are generated through certain wallets/APIs.
	e.g.
    	1. Wallets in browser (Metamask / Phantom)

    	2. Dart
        		(https://pub.dev/packages/eth_sig_util)

    	3. Python
        		(https://pypi.org/project/eth-account/)

in Python it can be created as:

	from eth_account.messages import encode_defunct
	from eth_account import Account

	msg="<Message received from the pre-login response>"
	signature = sign(msg)

	def sign(msg):
	#
		# Hexadecimal key (private key)
		key = "<Your-Private-Key>"

		# Create the message hash
		msghash = encode_defunct(text=msg)

		# Sign the message
		signature = Account.sign_message(msghash, key)
		return "0x" + signature.signature.hex()
	#
Responses
200
200 response
application/json
400
400 response
application/json
401
401 response
application/json
402
402 response
application/json
post
POST //proof/v1/{proof_type}/login HTTP/1.1
Host: api.witnesschain.com
Cookie: text
Content-Type: application/json
Accept: */*
Content-Length: 20

{
  "signature": "text"
}
{
  "result": {
    "success": true
  }
}
post

Request to create a new challenge using DCL contracts.

Before calling this api 'submitRequest()' smart contract must be called.

And the 'challenge_id' after calling the 'submitRequest' must be provided.
Authorizations
Path parameters
proof_typestringRequired
Header parameters
CookiestringRequired

The cookies that were received after calling '/login' API.
Body
challenge_idstringRequired

The challenge_id that was generated after calling the
DCL 'submitRequest' smart contract.
Responses
200
200 response
application/json
400
400 response
application/json
401
401 response
application/json
post
POST //proof/v1/{proof_type}/challenge-request-dcl HTTP/1.1
Host: api.witnesschain.com
Cookie: text
Content-Type: application/json
Accept: */*
Content-Length: 23

{
  "challenge_id": "text"
}
{
  "result": {
    "challenge_id": "text",
    "challenge_status": "SUBMITTED_TO_CHALLENGE_COORDINATOR"
  }
}
  • Step 1: Pre-login and login
  • POST/proof/v1/{proof_type}/pre-login
  • POST/proof/v1/{proof_type}/login
  • Step 2: Submit an on-chain Challenge Request
  • Step 3: Trigger a Challenge with the Witness Chain Broker
  • POST/proof/v1/{proof_type}/challenge-request-dcl
  • Step 4: Monitor the status of the Challenge to obtain the results
  • POST/proof/v1/{proof_type}/challenge-status-dcl
post

Get the status of a given DCL challenge.
Authorizations
Path parameters
proof_typestringRequired
Header parameters
CookiestringRequired

The cookies that were received after calling '/login' API.
Body
challenge_idstringRequired

The challenge_id that was generated after calling the
DCL 'submitRequest' smart contract.
Responses
200
200 response
application/json
400
400 response
application/json
401
401 response
application/json
post
POST //proof/v1/{proof_type}/challenge-status-dcl HTTP/1.1
Host: api.witnesschain.com
Cookie: text
Content-Type: application/json
Accept: */*
Content-Length: 23

{
  "challenge_id": "text"
}
{
  "id": "text",
  "challenge_parameters": {
    "number_of_challengers": 1,
    "{other-challenge-parameter-1}": "text",
    "{other-challenge-parameter-2}": "text",
    "{other-challenge-parameter-3}": "text",
    "{other-challenge-parameter-N}": "text"
  },
  "challenge_start_time": "text",
  "challenge_end_time": "text",
  "consolidated_result": {
    "{consolidated-result-parameter-1}": "text",
    "{consolidated-result-parameter-2}": "text",
    "{consolidated-result-parameter-3}": "text",
    "{consolidated-result-parameter-N}": "text"
  },
  "prover": {
    "claims": {
      "{claim-parameter-1}": "text",
      "{claim-parameter-2}": "text",
      "{claim-parameter-N}": "text"
    }
  },
  "state": "SUBMITTED_TO_CHALLENGE_COORDINATOR"
}