Advanced authorization

Advanced authorization provides a higher level of security. It requires public and private keys, a timestamp, and a generated request signature.

const crypto = require("crypto");

const publicKey = "YOUR_PUBLIC_KEY"; // put here your public key
const privateKey = "YOUR_PRIVATE_KEY"; // put here your private key

// Get UTC time in milliseconds
const timestamp = Date.now();

const url = "https://api.numapay.com";
const method = "GET"
const path = "/api/v1/account";
const body = {}; // empty object for GET request

// Hashing signature
const signature = crypto
  .createHmac("sha256", privateKey)
  .update(timestamp + method + path + JSON.stringify(body))
  .digest("hex");

const options = {
  method,
  headers: {
    accept: "application/json",
    "Content-Type": "application/json",
    "x-public-key": publicKey,
    "x-timestamp": timestamp.toString(),
    "x-signature": signature,
  },
};

fetch(url + path, options)
  .then((response) => response.json())
  .then((showResponse) => console.log(showResponse.data));