Getting Started
Installing Ambitorio SDK
To use this package, the following prerequisites are needed:
- Node 16 or higher
Install by using the following command:
npm install @ambitorio\ambitorio-sdk
Using Ambitorio SDK
The Ambitorio SDK can be used in two ways:
- A stateful class that implements functions and automations to make it very easy to manage access.
- Single functions allowing for full flexibility.
Stateful class
The stateful object contains most of the functions needed for the Proof of Key process. However, it additionally adds some ease of use features mainly to make managing access tokens easier.
To create a new class object, the object can be easily created by using the new
declaration:
import { Ambitorio } from "@ambitorio/ambitorio-sdk/dist/Ambitorio";
const ambitorio = new Ambitorio();
Functions can be accessed directly via the object. If you are using Typescript, all functions are additionally typed and can appear as suggestions. An example usage would be as follows:
import { Ambitorio } from "@ambitorio/ambitorio-sdk/dist/Ambitorio";
const ambitorio = new Ambitorio();
ambitorio.validateAccessToken("token");
The biggest advantage with this class is that the object holds a list of access tokens which the user received after going through the Proof of Key access tokens. More information about this can be read in the page “Managing access tokens”.
Single functions
The SDK can be used to specifically import functions that are needed. An example of this:
import {
sendSignedChallengeToServer,
signChallenge,
} from "@ambitorio/ambitorio-sdk/dist/services/challenge";
const signedChallenge = await signChallenge(challenge, token);
const challengeResult = await sendSignedChallengeToServer(
challenge,
signedChallenge
);