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

@decentralchain/browser-bus

Package Overview
Dependencies
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@decentralchain/browser-bus

Cross-window browser communication library for DecentralChain DApps and wallet applications

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
3
Created
Source

DecentralChain

@decentralchain/browser-bus

Cross-window browser communication library for DecentralChain DApps and wallet applications.

npm license bundle size node

Overview

Enables secure message passing between browser windows, tabs, and iframes using the postMessage API. Used for DApp-to-wallet communication, transaction signing popups, and multi-tab synchronization.

Part of the DecentralChain SDK.

Installation

npm install @decentralchain/browser-bus

Requires Node.js >= 24 and an ESM environment ("type": "module").

Quick Start

Parent window with iframe

import { Bus, WindowAdapter } from '@decentralchain/browser-bus';

const url = 'https://some-iframe-content-url.com';
const iframe = document.createElement('iframe');

WindowAdapter.createSimpleWindowAdapter(iframe).then((adapter) => {
  const bus = new Bus(adapter);

  bus.once('ready', () => {
    // Received message from iframe
  });
});
iframe.src = url;
document.body.appendChild(iframe);

Iframe side

import { Bus, WindowAdapter } from '@decentralchain/browser-bus';

WindowAdapter.createSimpleWindowAdapter().then((adapter) => {
  const bus = new Bus(adapter);

  bus.dispatchEvent('ready', null);
});

API Reference

Bus

Creates a bus instance for sending and receiving events and requests.

Constructor:

  • adapter — an Adapter instance for the messaging transport
  • timeout (optional) — default response timeout in milliseconds (default: 5000)

dispatchEvent(name, data)

Send an event to all connected Bus instances.

bus.dispatchEvent('some-event-name', jsonLikeData);

request(name, data?, timeout?)

Send a request and receive a response. Returns a Promise.

const result = await bus.request('some-method', jsonLikeData, 100);

on(name, handler)

Subscribe to an event.

bus.on('some-event', (data) => {
  // handle event
});

once(name, handler)

Subscribe to an event once.

bus.once('some-event', (data) => {
  // fires only once
});

off(eventName?, handler?)

Unsubscribe from events.

bus.off('some-event', handler); // Unsubscribe specific handler
bus.off('some-event'); // Unsubscribe all from 'some-event'
bus.off(); // Unsubscribe from everything

registerRequestHandler(name, handler)

Register a handler for incoming requests.

bus.registerRequestHandler('get-random', () => Math.random());

Handlers may return Promises:

bus.registerRequestHandler('get-data', () => Promise.resolve(someData));

WindowAdapter

Adapter implementation for cross-window communication via postMessage.

WindowAdapter.createSimpleWindowAdapter(iframe?, options?)

Factory method that creates a WindowAdapter for simple parent/iframe communication.

Adapter

Abstract base class for custom transport implementations.

Development

Prerequisites

  • Node.js >= 24 (see .node-version)
  • npm >= 10

Setup

git clone https://github.com/Decentral-America/browser-bus.git
cd browser-bus
npm install

Scripts

CommandDescription
npm run buildBuild distribution files
npm testRun tests with Vitest
npm run test:watchTests in watch mode
npm run test:coverageTests with V8 coverage
npm run typecheckTypeScript type checking
npm run lintESLint
npm run lint:fixESLint with auto-fix
npm run formatFormat with Prettier
npm run validateFull CI validation pipeline
npm run bulletproofFormat + lint fix + typecheck + test
npm run bulletproof:checkCI-safe: check format + lint + tc + test

Quality Gates

  • ESLint with strict TypeScript rules
  • Prettier formatting
  • 90%+ code coverage thresholds
  • Bundle size budget enforcement
  • Package export validation (publint + attw)
PackageDescription
@decentralchain/signerTransaction signing orchestrator
@decentralchain/cubensis-connect-providerCubensisConnect wallet provider
@decentralchain/signature-adapterMulti-provider signing adapter

Contributing

See CONTRIBUTING.md.

Security

To report a vulnerability, see SECURITY.md.

License

MIT — Copyright (c) DecentralChain

Keywords

decentralchain

FAQs

Package last updated on 05 Mar 2026

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