New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

chronosnet-js

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chronosnet-js

JavaScript SDK for ChronosNet - A distributed temporal consensus network

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

ChronosNet JavaScript SDK

A comprehensive JavaScript/TypeScript client for integrating with ChronosNet temporal anchoring and decentralized networking platform.

Installation

npm install chronosnet-js

or

yarn add chronosnet-js

Requirements

  • Node.js 16+ or modern browsers with ES2020 support

Quick Start

Node.js / Server-side

import { ChronosNet } from 'chronosnet-js';

// Create and start a node
const node = new ChronosNet({
  nodeId: 'my-js-node',
  apiPort: 8081
});

await node.start();

// Create an event with error handling for SDK parsing issue
try {
  const event = await node.createEvent({
    data: { message: 'Hello from JavaScript!' },
    eventType: 'greeting'
  });
  console.log('Event created:', event.eventId);
} catch (error) {
  // Handle SDK parsing issue - successful HTTP 200 responses reported as errors
  if (error.message && error.message.includes('HTTP 200') && error.message.includes('event_id')) {
    // Extract event data from error message
    const eventMatch = error.message.match(/{"event_id":.*}/);
    if (eventMatch) {
      const eventData = JSON.parse(eventMatch[0]);
      console.log('Event created (from HTTP 200):', eventData.event_id);
    } else {
      console.error('Failed to extract event data from error message');
    }
  } else {
    // Re-throw other errors
    throw error;
  }
}

// Get all events
const events = await node.getEvents();
console.log(`Total events: ${events.length}`);

Browser / Client-side

import { ChronosNetClient } from 'chronosnet-js';

// Connect to existing node
const client = new ChronosNetClient({
  baseUrl: 'http://localhost:8081'
});

// Create an event with error handling for SDK parsing issue
try {
  const event = await client.createEvent({
    data: { user: 'alice', action: 'login' },
    eventType: 'user_action'
  });
  console.log('Event created:', event.eventId);
} catch (error) {
  // Handle SDK parsing issue - successful HTTP 200 responses reported as errors
  if (error.message && error.message.includes('HTTP 200') && error.message.includes('event_id')) {
    // Extract event data from error message
    const eventMatch = error.message.match(/{"event_id":.*}/);
    if (eventMatch) {
      const eventData = JSON.parse(eventMatch[0]);
      console.log('Event created (from HTTP 200):', eventData.event_id);
    } else {
      console.error('Failed to extract event data from error message');
    }
  } else {
    // Re-throw other errors
    throw error;
  }
}

// Query events
const events = await client.queryEvents({
  eventType: 'user_action',
  limit: 10
});

console.log('Recent events:', events);

SDK Parsing Issue Utility

Known Issue: The ChronosNet SDK may incorrectly report successful HTTP 200 responses as errors when creating events. Despite the error, events are actually created successfully with valid event IDs, temporal proofs, and causal parent references. Use the utility functions below to handle this issue.

import { createEventWithErrorHandling, extractEventFromError } from 'chronosnet-js';

// Using the utility function
const client = new ChronosNetClient({
  baseUrl: 'http://localhost:8081'
});

// Using the wrapper function
const event = await createEventWithErrorHandling(client, {
  data: { message: 'Testing error handling' },
  eventType: 'test_event'
});

console.log('Event created with ID:', event.event_id);

Error Handling

import { ChronosNetClient, ChronosNetError, ValidationError, NetworkError } from 'chronosnet-js';

try {
  const event = await client.createEvent({
    data: { invalid: 'data' },
    eventType: 'test'
  });
} catch (error) {
  if (error instanceof ValidationError) {
    console.error('Validation failed:', error.details);
  } else if (error instanceof NetworkError) {
    console.error('Network error:', error.message);
    // Retry logic here
  } else if (error instanceof ChronosNetError) {
    console.error('ChronosNet error:', error.code, error.message);
  } else {
    console.error('Unexpected error:', error);
  }
}

API Reference

ChronosNet Class (Node.js)

Full Node Implementation for server-side applications and full ChronosNet nodes.

Constructor

new ChronosNet(options: {
  nodeId: string;
  apiPort?: number;
  p2pPort?: number;
  vdfDifficulty?: number;
})

Creates a new ChronosNet node instance with the specified configuration.

Core Methods

  • async start(): Promise<void> - Start the ChronosNet node and all services
  • async createEvent(options): Promise<Event> - Create a new temporal event
  • async getEvents(options?): Promise<Event[]> - Get events with optional filtering
  • async getStatus(): Promise<NodeStatus> - Get node health and statistics

ChronosNetClient Class (Browser)

HTTP Client Implementation for browser applications and lightweight integrations.

Constructor

new ChronosNetClient(options: {
  baseUrl: string;
  timeout?: number;
  headers?: Record<string, string>;
})

Creates a client to connect to an existing ChronosNet node via HTTP.

HTTP Methods

  • async createEvent(options): Promise<Event> - Create event via REST API
  • async queryEvents(filters): Promise<Event[]> - Advanced event querying
  • async getNodeStatus(): Promise<NodeStatus> - Get node health and statistics

License

MIT

Keywords

chronosnet

FAQs

Package last updated on 30 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts