API Reference
Gateway API Overview

Gateway API Overview

The Polybase DB Gateway REST API provides a convenient way to access the Polybase DB decentralized network.

⚠️

While the Polybase DB network is in Alpha, the gateway is the only way to access the Polybase DB network. We will shortly be adding p2p access to the network.

Authentication

The Polybase DB Gatweay API uses public/private key pair for authentication. That means it works natively with wallets like Metamask.

Authentication is composed of:

  • v the version being used, should be v=0
  • t current unix timestamp in milliseconds
  • h type of hash signing being used eth-personal-sign is currently the only allowed option
  • sig the signature of the data (see below)
  • pk optional 64 byte public key (secp256k1 algorithm)

An example of a valid authroization:

v=0,t=1671884992,h=eth-personal-sign,sig=0x288db6271d92253ae19983a8e5110f1bc1bef1911210127ccbf657d85428ba9917aa9457f0f8e7f300a36b106525d3a3471e63ae265af4898742040a377e1da11c

The token is passed in the X-Polybase-Signature header of the request.

Signature (sig)

To generate sig you must sign a string in the format <timestamp>.<body_json>. Where timestamp is the t you provided above, and body_json is the body of the request (as a JSON string).

You can use the @polybase/util (opens in a new tab) package to generate the signature from any 32 bytes private key, and the sign function to create the signature.

import { secp256k1 } from '@polybase/util'
 
// You can use any 32 byte private key from any library, 
// here is an example from @polybase/util
let private_key = secp256k1.generatePrivateKey();
 
function createSig (timestamp, body) {
  const str_to_sign = `${timestamp}.${JSON.stringify(body)}`;
  return secp256k1.sign(privateKey, str_to_sign);
}

Polybase DB Docs