Getting Started

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

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
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"
  }
}

Login

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

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
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
  }
}

Step 2: Submit an on-chain Challenge Request

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

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

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

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

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
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"
}

Last updated