Node.js server SDK v0.0.2
Installation​
Pick one of the following methods to install the SDK.
- npm
- yarn
Run the following command in your terminal.
npm i -S @blindnet/sdk-node
Run the following command in your terminal.
yarn add @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​
name | type | required | description |
---|---|---|---|
appKey | string | true | Application private key |
appId | string | true | Application ID |
endpoint | string | false | Endpoint 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​
name | type | required | description |
---|---|---|---|
userId | string | true | ID of a registered user. |
groupId | string | true | ID 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​
name | type | required | description |
---|---|---|---|
appKey | string | true | Application private key |
appId | string | true | Application ID |
userId | string | true | ID of a registered user. |
groupId | string | true | ID 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​
name | type | required | description |
---|---|---|---|
param | string | string[] | true | ID 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​
name | type | required | description |
---|---|---|---|
appKey | string | true | Application private key |
appId | string | true | Application ID |
userId | string | true | ID of a registered user. |
param | string | string[] | true | ID 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​
name | type | required | description |
---|---|---|---|
dataId | string | true | ID of a data to be deleted. |
Return type​
Promise<void>
The operation succeeded if an exception wasn't thrown.
Errors​
type | description |
---|---|
AuthenticationError | Client token has expired or is invalid. A wrong application key or application id is provided. Generate a new token and call refreshToken. |
BlindnetServiceError | Error on blindnet server. |
Revoking access to users​
Deletes all encrypted data keys of a given user.
async function revokeAccess(userId: string): Promise<void>
Parameters​
name | type | required | description |
---|---|---|---|
userId | string | true | ID of a user to revoke access to the encrypted data. |
Return type​
Promise<void>
The operation succeeded if an exception wasn't thrown.
Errors​
type | description |
---|---|
AuthenticationError | Client token has expired or is invalid. A wrong application key or application id is provided. Generate a new token and call refreshToken. |
BlindnetServiceError | Error on blindnet server. |
Deleting users​
Deletes a user from blindnet.
async function forgetUser(userId: string): Promise<void>
Parameters​
name | type | required | description |
---|---|---|---|
userId | string | true | ID of a user to delete. |
Return type​
Promise<void>
The operation succeeded if an exception wasn't thrown.
Errors​
type | description |
---|---|
AuthenticationError | Client token has expired or is invalid. A wrong application key or application id is provided. Generate a new token and call refreshToken. |
BlindnetServiceError | Error 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​
name | type | required | description |
---|---|---|---|
groupId | string | true | ID of a group to delete. |
Return type​
Promise<void>
The operation succeeded if an exception wasn't thrown.
Errors​
type | description |
---|---|
AuthenticationError | Client token has expired or is invalid. A wrong application key or application id is provided. Generate a new token and call refreshToken. |
BlindnetServiceError | Error on blindnet server. |