Skip to main content

Node.js server SDK v0.0.2

Installation

Pick one of the following methods to install the SDK.

Run the following command in your terminal.

npm i -S @blindnet/sdk-node

Imports

const Blindnet = require('@blindnet/sdk-node')

Initialization

blindnet devkit must be initialized before you can use it (with the exception of the static token generation methods).

static async function init(
appKey: string,
appId: string,
endpoint?: string
): Blindnet

Parameters

nametyperequireddescription
appKeystringtrueApplication private key
appIdstringtrueApplication ID
endpointstringfalseEndpoint of the blindnet server. Default value is https://api.blindnet.io. For testing, use https://test.blindnet.io.

Return type

Blindnet (An instance which you use to call SDK methods.)

Creating user tokens

Two types of tokens are needed: tokens for registered users and temporary tokens.

Create a token for a registered user

These tokens are used by the registered users to invoke SDK methods.

function createUserToken(userId: string, groupId?: string): Promise<string>

Parameters

nametyperequireddescription
userIdstringtrueID of a registered user.
groupIdstringtrueID of the group to which a registered user belongs.

Return type

Promise<string>

A static method can also be used.

static function createUserToken(
appKey: string,
appId: string,
userId: string,
groupId?: string
): Promise<string>

Parameters

nametyperequireddescription
appKeystringtrueApplication private key
appIdstringtrueApplication ID
userIdstringtrueID of a registered user.
groupIdstringtrueID of the group to which a registered user belongs.

Return type

Promise<string>

Create a temporary token

Creates a token for non-registered users of your application, usually data senders. When this token is used for encrypting data, all specified users or users that belong to a specified group will have access to the encrypted data.

function createTempUserToken(param: string | string[]): Promise<string>

Parameters

nametyperequireddescription
paramstring | string[]trueID of the group for which the data is being encrypted OR list of IDs of users to whom the data is being encrypted.

Return type

Promise<string>

A static method can also be used.

static function createTempUserToken(
appKey: string,
appId: string,
param: string | string[]
): Promise<string>

Parameters

nametyperequireddescription
appKeystringtrueApplication private key
appIdstringtrueApplication ID
userIdstringtrueID of a registered user.
paramstring | string[]trueID of the group for which the data is being encrypted OR list of IDs of users to whom the data is being encrypted.

Return type

Promise<string>

Deleting data keys

Deletes the encrypted data key from blindnet.

async function forgetData(dataId: string): Promise<void>

Parameters

nametyperequireddescription
dataIdstringtrueID of a data to be deleted.

Return type

Promise<void>

The operation succeeded if an exception wasn't thrown.

Errors

typedescription
AuthenticationErrorClient token has expired or is invalid. A wrong application key or application id is provided. Generate a new token and call refreshToken.
BlindnetServiceErrorError on blindnet server.

Revoking access to users

Deletes all encrypted data keys of a given user.

async function revokeAccess(userId: string): Promise<void>

Parameters

nametyperequireddescription
userIdstringtrueID of a user to revoke access to the encrypted data.

Return type

Promise<void>

The operation succeeded if an exception wasn't thrown.

Errors

typedescription
AuthenticationErrorClient token has expired or is invalid. A wrong application key or application id is provided. Generate a new token and call refreshToken.
BlindnetServiceErrorError on blindnet server.

Deleting users

Deletes a user from blindnet.

async function forgetUser(userId: string): Promise<void>

Parameters

nametyperequireddescription
userIdstringtrueID of a user to delete.

Return type

Promise<void>

The operation succeeded if an exception wasn't thrown.

Errors

typedescription
AuthenticationErrorClient token has expired or is invalid. A wrong application key or application id is provided. Generate a new token and call refreshToken.
BlindnetServiceErrorError on blindnet server.

Deleting user groups

Deletes all encrypted data keys of a given user.
Deletes all users that belong to the group and all their encrypted data keys.

async function forgetGroup(groupId: string): Promise<void>

Parameters

nametyperequireddescription
groupIdstringtrueID of a group to delete.

Return type

Promise<void>

The operation succeeded if an exception wasn't thrown.

Errors

typedescription
AuthenticationErrorClient token has expired or is invalid. A wrong application key or application id is provided. Generate a new token and call refreshToken.
BlindnetServiceErrorError on blindnet server.