1. Docs


Initialization sets the context of your app to a logged in user with a specific set of device keys. It is required before document, group or current user methods can be accessed. The IronNode SDK provides methods for managing users and generating the details required to initialize the SDK.


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


Parameter Name Value Description
accountID string The ID of the account that the SDK should act on behalf of.
segmentID number The internal ID of the segment to which the user belongs. 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 user’s 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 user’s 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.


Returns a Promise that resolves with an object that exposes the various document, group, and current user SDK methods. The response also contains a userContext property which contains key rotation information for the currently initialized user. This information can be used to determine if the private key of user who was just initialized requires rotation or if the user is an admin of any group whose private key requires rotation.

{ document: Document SDK, group: Group SDK, user: User SDK, userContext: { userNeedsRotation: boolean, groupsNeedingRotation: string[] } }


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) => { if(SDK.userContext.needsRotation || SDK.userContext.groupsNeedingRotation.length > 0){ //Rotate users key via SDK.user.rotateMasterKey(..) or //rotate group keys via SDK.group.rotatePrivateKey(..) } //Initialization successful! Use the resolved SDK object to list documents //available to the user return SDK.document.list(); }) .then((documents) => { console.log(documents); });

Was this page helpful?