npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bithive/relayer-api

v0.1.7-beta.1

Published

BitHive Relayer API

Downloads

33

Readme

BitHive Relayer API

Stake Bitcoin to BitHive with Relayer API.

Introduction

@bithive/relayer-api is a library that provides a simple interface for staking Bitcoin to BitHive with minimal efforts. It is designed to be used in the browser and Node.js. It acts as a client for the BitHive Relayer.

Installation

pnpm install @bithive/relayer-api

Usage

Stake Bitcoin

import { createRelayerClient } from '@bithive/relayer-api';

// Create a relayer client
const relayer = createRelayerClient({ url: config.relayerRpcUrl });

// User public key (compressed)
const publicKey = '0277...288a';

// User address
// Supported Address Types
// - Native Segwit (P2WPKH)
// - Nested Segwit (P2SH-P2WPKH)
// - Taproot       (P2TR)
// - Legacy        (P2PKH)
const address = 'tb1q...wrh8';

// Bitcoin amount that is within the valid scope
// e.g. between 0.005 and 0.1 BTC
const amount = 1000000; // 0.01 BTC

// BTC provider with `signPsbt` interface
const provider = window.unisat; // UniSat wallet

// 1. Build the PSBT that is ready for signing
const { psbt: unsignedPsbt } = await relayer.deposit.buildUnsignedPsbt({
  publicKey,
  address,
  amount,
  // Optional: specify `fee` or `feeRate` here if needed
});

// 2. Sign and finalize the PSBT with wallet
if (!provider.signPsbt) {
  throw Error('signPsbt is not supported');
}
const signedPsbt = await provider.signPsbt(unsignedPsbt);

// 3. Submit the finalized PSBT for broadcasting and relaying
await relayer.deposit.submitFinalizedPsbt({
  psbt: signedPsbt,
});

Unstake Bitcoin

import { createRelayerClient } from '@bithive/relayer-api';

// Create a relayer client
const relayer = createRelayerClient({ url: config.relayerRpcUrl });

// User public key (compressed)
const publicKey = '0277...288a';

// BTC provider with `signMessage` interface
const provider = window.unisat; // UniSat wallet

// Get the deposits by public key
const { deposits } = await relayer.user.getDeposits({
  publicKey,
});

// Find the first confirmed deposit
const confirmedDeposit = deposits.find(
  (deposit) =>
    ['DepositConfirmed', 'DepositConfirmedInvalid'].includes(
      deposit.status,
    ),
);

if (!confirmedDeposit) {
  throw Error('No confirmed deposit that is ready to unstake');
}

// 1. Build the unstaking message that is ready for signing
const { message } = await relayer.unstake.buildUnsignedMessage({
  deposits: [{
    txHash: confirmedDeposit.depositTxHash,
    vout: confirmedDeposit.depositVout,
  }],
  publicKey,
});

// 2. Sign the unstaking message with wallet
if (!provider.signMessage) {
  throw Error('signMessage is not supported');
}
const signature = await provider.signMessage(message);

// 3. Submit the unstaking signature and relay to BitHive contract on NEAR
await relayer.unstake.submitSignature({
  deposits: [{
    txHash: confirmedDeposit.depositTxHash,
    vout: confirmedDeposit.depositVout,
  }],
  publicKey,
  signature: Buffer.from(signature, 'base64').toString('hex'),
});

Withdraw Bitcoin

import { createRelayerClient } from '@bithive/relayer-api';

// Create a relayer client
const relayer = createRelayerClient({ url: config.relayerRpcUrl });

// User public key (compressed)
const publicKey = '0277...288a';

// Recipient address (can be different with user address)
const recipientAddress = 'tb1q...wrh8';

// BTC provider with `signPsbt` interface
const provider = window.unisat; // UniSat wallet

// Get the account info by public key
const { account } = await relayer.user.getAccount({
  publicKey,
});

let partiallySignedPsbt: string | undefined = undefined;

if (account.pendingSignPsbt) {
  // If there's a pending PSBT for signing, user cannot request signing a new PSBT
  partiallySignedPsbt = account.pendingSignPsbt.psbt;
} else {
  // Get the deposits by public key
  const { deposits } = await relayer.user.getDeposits({
    publicKey,
  });

  // Find the first deposit that is ready to withdraw
  const unstakedDeposit = deposits.find(
    (deposit) =>
      ['UnstakeConfirmed'].includes(deposit.status),
  );

  // 1. Build the PSBT that is ready for signing
  const { psbt: unsignedPsbt } = await relayer.withdraw.buildUnsignedPsbt({
    deposits: {
      txHash: unstakedDeposit.depositTxHash,
      vout: unstakedDeposit.depositVout,
    },
    recipientAddress,
    publicKey,
    // Optional: specify `fee` or `feeRate` here if needed
  });

  // 2. Sign the PSBT with wallet. Don't finalize it.
  if (!provider.signPsbt) {
    throw Error('signPsbt is not supported');
  }
  partiallySignedPsbt = await provider.signPsbt(unsignedPsbt, {
    autoFinalized: false,
    toSignInputs: [{
      index: 0,
      publicKey,
    }],
  });
}

// 3. Sign the PSBT with NEAR Chain Signatures
const { psbt: fullySignedPsbt } = await relayer.withdraw.chainSignPsbt({
  psbt: partiallySignedPsbt,
});

// 4. Submit the finalized PSBT for broadcasting and relaying
await relayer.withdraw.submitFinalizedPsbt({
  psbt: fullySignedPsbt,
});