Skip to main content

Node.js API Reference

Overview​

This page documents the Node.js accessor API: constructors, lifecycle methods, input ports, output handlers, runtime parameters, and helper methods.

The Node.js API is implemented in entity/node/accessors/. The four classes are:

SecureCommClient​

const SecureCommClient = require('../accessors/SecureCommClient');

Constructor​

const client = new SecureCommClient(configFilePath);

Loads an entity config (JSON with .config extension) from configFilePath. Generated configs live under entity/node/example_entities/configs/.

initialize()​

client.initialize();

Sets up distribution-key state, output slots, and output handlers. Does not open a connection.

provideInput(port, value)​

PortValue typeBehavior
'serverHostPort'{host, port}Requests a session key and performs the SST handshake with the target.
'serverHostPort'nullCloses the current secure client socket.
'toSend'BufferEncrypts and sends data over the active connection.
client.provideInput('serverHostPort', { host: 'localhost', port: 21100 });
client.provideInput('toSend', Buffer.from('hello'));
client.provideInput('serverHostPort', null);

provideInputResource(port, value, resourceName)​

client.provideInputResource('serverHostPort', { host: 'localhost', port: 21100 }, 'myResource');

Variant of provideInput that includes a resource name in the session key purpose, enabling fine-grained per-resource access control.

setOutputHandler(key, handler)​

client.setOutputHandler('connected', (connected) => {});
client.setOutputHandler('received', (data) => {});
client.setOutputHandler('error', (message) => {});
client.setOutputHandler('privilege', (result) => {});

Output handler keys:

KeyHandler valueWhen fired
'connected'booleantrue when handshake completes; false when connection closes.
'received'BufferDecrypted data received from the server.
'error'stringError message (auth failure, handshake error, migration, etc.).
'privilege'objectResult of a DelegationGrant or DelegationRevoke operation.

latestOutput(key)​

const data = client.latestOutput('received');
const isConnected = client.latestOutput('connected');

Returns the most recently stored value for a given output key.

setParameter(key, value)​

client.setParameter('numKeysPerRequest', 5);
client.setParameter('migrationEnabled', true);

Runtime parameters:

ParameterDefaultMeaning
numKeysPerRequest1Session keys requested per operation.
migrationEnabledfalseEnables automatic Auth failover.
authFailureThreshold3Auth failures before migration is triggered.
migrationFailureThreshold3Migration failures before rotating targets.
keyId—Specific session key ID for experiment paths.

Helper methods​

MethodReturnsDescription
getTargetServerInfoList()arrayReturns configured target servers: [{name, host, port}, ...].
getEntityInfo()objectReturns entity metadata from the config.
showKeys()stringFormatted string of distribution key and cached session keys.
showSocket()stringFormatted string of current socket state.
getSessionKeysForCaching(numKeys)voidRequests {group: 'Servers'} session keys for future connections.
getSessionKeyIdForGrantAccess(numKeys, trustLevel)voidRequests a session key ID for a delegation grant; prints as JSON to stdout. trustLevel can be 'HighTrustAgents', 'MediumTrustAgents', or 'LowTrustAgents'.
getSessionKeysForGrantAccess(keyId)voidRetrieves full session keys for keyId; prints as JSON to stdout and exits. Used by agent entities.
getSessionKeysForWebsite(keyId)voidLike getSessionKeysForGrantAccess but also includes the owner group in the output, for trust-level verification. Used by website entities.
performPrivilege(type, subject, object, validity)voidSends a delegation request to Auth. type: 'DelegationGrant' or 'DelegationRevoke'. validity: e.g. '1*day' or null. Fires the 'privilege' handler on completion.
migrateToTrustedAuth()voidManually triggers migration to the next Auth in migrationInfo.
setEntityInfo(key, value)voidMutates entity config at runtime.

SecureCommServer​

const SecureCommServer = require('../accessors/SecureCommServer');

Constructor​

const server = new SecureCommServer(configFilePath);

Loads a server entity config. Server configs include a listeningServerInfo field with the port to bind.

initialize()​

server.initialize();

Sets up distribution-key state, output handlers, and starts the secure TCP listener on the configured port.

provideInput(port, value)​

PortValue typeBehavior
'toSend'{data: Buffer, id: number}Encrypts and sends data to the client identified by id.
'toSend'{data: Buffer, id: null}Broadcasts data to all connected clients.
'toSend'nullCloses all client connections.

setOutputHandler(key, handler)​

server.setOutputHandler('listening', (port) => {});
server.setOutputHandler('connection', (info) => {});
server.setOutputHandler('received', (received) => {});
server.setOutputHandler('error', (info) => {});

Output handler keys:

KeyHandler valueWhen fired
'listening'numberPort the server is listening on, after initialize().
'connection'stringHuman-readable connection/disconnection event message.
'received'{data: Buffer, id: number}Decrypted data from a client socket identified by id.
'receivedID'{data: Buffer, id: number}Alias for 'received'.
'error'stringError details including socket ID and description.

latestOutput(key)​

Returns the most recently stored value for a given output key.

setParameter(key, value)​

ParameterMeaning
migrationEnabledEnables Auth failover.
authFailureThresholdAuth failures before migration.
migrationFailureThresholdMigration failures before rotating targets.

Helper methods​

MethodReturnsDescription
getEntityInfo()objectReturns entity metadata from the config.
showKeys()stringFormatted string of distribution key and cached session keys.
showSocket()stringFormatted string of all connected client sockets.
getSessionKeysForFutureClients(numKeys)voidPre-requests {cachedKeys: 101} session keys for upcoming client handshakes.
getSessionKeysForPublish(numKeys)voidRequests {pubTopic: 'Ptopic'} session keys for publish scenarios.
migrateToTrustedAuth()voidManually triggers Auth migration.
setEntityInfo(key, value)voidMutates entity config at runtime.

SecurePublisher​

const SecurePublisher = require('../accessors/SecurePublisher');

Constructor and initialization​

const pub = new SecurePublisher(configFilePath);
pub.setParameter('numKeysPerRequest', 1);
pub.setParameter('topic', 'Ptopic');
pub.initialize();

initialize() connects to the MQTT broker (TCP) or creates a UDP broadcast socket, then requests session keys.

provideInput('toPublish', value)​

pub.provideInput('toPublish', Buffer.from('payload'));

Encrypts and publishes the message using the current session key. Increments the sequence number automatically.

setOutputHandler output keys​

KeyHandler valueWhen fired
'connection'stringConnection established.
'error'stringError occurred.
'ready'stringSession keys have been obtained; publisher is ready.

Parameters​

ParameterDefaultMeaning
numKeysPerRequest1Session keys to request from Auth.
topicnullMQTT publish topic (TCP mode).

Protocol support​

  • TCP (distProtocol: 'TCP'): publishes encrypted data to an MQTT broker.
  • UDP (distProtocol: 'UDP'): broadcasts encrypted data to 255.255.255.255:8088.

SecureSubscriber​

const SecureSubscriber = require('../accessors/SecureSubscriber');

Constructor and initialization​

const sub = new SecureSubscriber(configFilePath);
sub.initialize();

initialize() sets up output handlers but does not start subscribing until provideInput('subscribe', ...) is called.

provideInput(port, value)​

PortValueBehavior
'subscribe'string or port numberSubscribes to the given MQTT topic or UDP port.
'unsubscribe'string or port numberUnsubscribes from the given topic or port.

setOutputHandler output keys​

KeyHandler valueWhen fired
'subscription'stringSubscribe/unsubscribe action completed.
'received'{data: Buffer, topic: string}Decrypted message arrived.
'connection'stringConnection established.
'error'stringError occurred.

Protocol support​

  • TCP: subscribes to an MQTT topic (e.g., 'Ptopic').
  • UDP: listens on the specified port for broadcast messages.

Config fields​

Node accessors read JSON config files generated by generateAll.sh. Relevant fields:

FieldMeaning
entityInfo.nameEntity name registered with Auth.
entityInfo.groupEntity group (e.g., Clients, Servers).
entityInfo.distProtocolTCP or UDP.
entityInfo.connectionTimeoutTimeout for connections (ms).
entityInfo.usePermanentDistKeyUse pre-shared symmetric distribution key.
authInfo.idAuth ID.
authInfo.hostAuth hostname.
authInfo.portAuth port.
authInfo.publicKeyAuth public key/certificate.
cryptoInfo.distributionCryptoSpecDistribution channel crypto spec.
cryptoInfo.sessionCryptoSpecSession key crypto spec.
listeningServerInfo.portListening port for server entities.
targetServerInfoList[{name, host, port}] — target servers for client entities.
migrationInfo[{host, port}] — alternate Auth endpoints for failover.