3.8.1 • Published 6 months ago

@keeex/keeex-api-sdk v3.8.1

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
-
Last release
6 months ago

@keeex/keeex-api-sdk

Provide access to the KeeeX API for timestamping and user management.

Installation

Use npm:

npm install @keeex/keeex-api-sdk

Usage

Import the KeeexAPI class and instantiate it with the authentication info. Authentication and tokens are renewed as needed.

A crypto-provider must be set before any operation can be done.

Example:

import KeeexAPI from "@keeex/keeex-api-sdk";
import "@keeex/crypto-provider-node";

const api = new KeeexAPI(
  "<userlogin>",
  "<userpassword>",
  "<app id>",
  {authToken: ""},
);

await api.timestamp("zuzi-ntinen");

const res = await api.getTimestampInfo("zuzi-ntinen");

console.log(res.topicIdx);

In the above example, the login and password are required, as well as the appId. An application can optionaly provide an authToken that was saved previously. If the token is still valid, it will be used, otherwise it will be automatically renewed.

If you do not provide credentials, you can still call the the getTimestampInfo method.

Get timestamp info

This method return timestamp information about an IDX.

You can either is authenticated or not but, beware that throttling might be applied if you are not.

/**
 * @param {string} idx
 */
const timestampInfo = await api.getTimestampInfo("zuzi-ntinen");

Get license file

This method return the license file either of the current authenticated user or the one required in the user option's parameter.

You MUST be authenticated to do this call.

/**
 * @param {GetLicenseParams} [options]
 * @param {string|number} [options.user] - If provided, will get the license of this user.
 *   /!\ Only works if authenticated user is from keeex
 * @param {string} [options.idx] - If provided, will download the license from the server
 *   only if the idx doesn't match
 */
// get own license
const licenseFile = await api.getLicense();
// get license for another user
const licenseFile = await api.getLicense({user: 1});
// don't download license if idx is the same as the one provided
const licenseFile = await api.getLicense({idx: "zuni-ntinen"});

Get remaining credits

This method return the remaining credits either for the current authenticated user or the one required in the user parameter.

You MUST be authenticated to do this call.

/**
 * @param {string|number} [user] - If provided, will get this user's remaining credits.
 *   /!\ Only works if authenticated user is from keeex
 */
// get own remaining credits
const remainingCredits = await api.remainingCredits();
// get remaining credits for another user
const remainingCredits = await api.remainingCredits(1);

Check permission

This method allow you to know if the current authenticated user or the one required in the user parameter can use 1 credit of selected types.

You MUST be authenticated to do this call.

/**
 * @param {boolean} keeex
 * @param {boolean} timestamp
 * @param {string|number} [user]
 **/
// check if current user can do 1 keeexing
const permissions = await api.checkPermission(true, false);
// check if another user can do 1 timestamping
cosnt permissions = await api.checkPermission(false, true, 1);

Use credits

This method use credit either of the current authenticated user or the one required in the user parameter.

You MUST be authenticated to do this call.

/**
 * @param {UserCredits} credits
 * @param {number} credits.keeex
 * @param {number} credits.timestamp
 * @param {string|number} [user] - If provided, will use this user's credits.
 *   /!\ Only works if authenticated user is from keeex
 */
// use own credits
await api.useCredits({keeex: 1, timestamp: 1});
// use credits for another user
await api.useCredits({keeex: 1, timestamp: 1}, 1);

Timestamp an idx

This method send timestamp request and consume either current authenticated user's credits or thoses of the required user in user parameter.

Unless you really need the out, you should do this call asynchronously for performance reason.

You MUST be authenticated to do this call.

/**
 * @param {string} idx
 * @param {string|number} [user] - If provided, will timestamp as this user.
 *   /!\ Only works if authenticated user is from keeex
 * @param {boolean} [countKeeexing] - If true, will also count a keeex credit
 * @param {string} [btcId]
 * @param {boolean} [asynchronous] - Default to false
 */
// timestamp idx and consume own timestamp credit
await api.timestamp("zuzi-ntinen");
// timestamp idx and consume another user timestamp and keeex credits, send along a btcId and do it
// asynchronously
await api.timestamp("zuzi-ntinen", 1, true, "<btcId>", true);

Get After string

This method return an after string containing a blockchain latest known block hash. As of writing this, it will be either ethereum or bitcoin blockchain.

You MUST be authenticated to do this call;

const afterString = await api.getAfterString();

Persistent authentication

By providing an old authToken it is possible to persist authentication across sessions. To get the new authToken obtained after the authentication process, the caller can provide a callback function that will be called everytime a new token is obtained. This callback must be provided as the newAuthTokenCB property of the options argument.

Build issue with webpack

The library tries to detect if it should use our certificate or not. When this detection fails, the module is not imported. Webpack can not know that ahead of time however, so it is necessary to add a few exclusion depending on your environment.

The following dependencies can be overloaded with nothing without issue:

  • https
  • socks-proxy-agent

Add this:

{
  resolve: {fallback: {"https": false}},
  externals: {"socks-proxy-agent": ""}
}

To webpack configuration.