Initialization

Initialization sets the context of your app to a logged in user on a specific set of device keys and is required before document group access. The IronNode SDK provides methods for managing users and generating the details required to initialize the SDK.

IronNode.initialize()

IronNode.initialize(accountID, segmentID, privateDeviceKey, privateSigningKey)

Parameters

Parameter Name Value Description
accountID string The ID of the account that the SDK should act on behalf of.
segmentID number The internal segment ID that the user is a part of. This value is NOT the segment ID provided within the IronCore admin console. This value is the segmentID property that is returned as part of the User.generateDeviceKeys method.
privateDeviceKey string A users private device key to use for SDK operations. The value should be base64 encoded bytes and is the deviceKeys.privateKey property that is returned from the User.generateDeviceKeys method.
privateSigningKey string A users private signing key to use for SDK operations. The value should be base64 encoded bytes and is the signingKeys.privateKey property that is returned from the User.generateDeviceKeys method.

Response

Returns a Promise that resolves with an object that exposes the various document and group SDK methods.

Example

The following shows an example of how you would generate a set of device keys for a specific user and use the results to initialize the IronNode SDK before calling a document list operation.

const IronNode = require("@ironcorelabs/ironnode");

//Generate a valid JWT for the user this script should act as
const userJWT = generateUserJWT();

//First verify that the user has already been synced within IronCore
IronNode.User.verify(userJWT)
  .then((verifyResult) => {
    if(!verifyResult){
      return console.error("User does not yet exist!");
    }
    //User exists, generate a new set of device keys for them
    return IronNode.User.generateDeviceKeys(userJWT, providedUserPassword);
  })
  .then((deviceKeyInfo) => {
    //Initialize the SDK with the details provided
    return IronNode.initialize(
      deviceKeyInfo.accountID,
      deviceKeyInfo.segmentID,
      deviceKeyInfo.deviceKeys.privateKey,
      deviceKeyInfo.signingKeys.privateKey
    );
  })
  .then((SDK) => {
    //Initialization successful! Use the resolved SDK object to list documents available to the user
    return SDK.document.list();
  })
  .then((documents) => {
    console.log(documents);
  });