Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@0xbridge/bitcoin-vault
Advanced tools
Bitcoin-psbt implementation TypeScript library supporting ESM and CJS.
@0xbridge/bitcoin-vault is a powerful TypeScript library for creating and signing Bitcoin PSBT transactions, working with Taproot scripts (such as multisig and timelock), and fetching UTXOs via public APIs. It is optimized for Testnet but can be configured for Mainnet or custom networks.
.
├── src/ # Source code
│ ├── constants.ts # API endpoints, OP_RETURN messages, and common constants
│ ├── transaction.ts # Core class for creating and signing PSBTs
│ ├── taproot.ts # Utilities for building Taproot scripts (multisig, timelock, etc.)
│ ├── utils.ts # Helper functions like fetchFeeRate, fetchUtxos, and selectUtxos
│ ├── types.ts # Type definitions for UTXOs, configurations, and more
│ └── index.ts # Main entry point exporting core modules
│
├── package.json # Project metadata and dependencies
├── tsconfig.*.json # TypeScript configurations for different builds
├── README.md # Documentation (this file)
Note: The dist/
folder is auto-generated after running the build script (npm run build
).
Install the library using your preferred package manager:
npm install @0xbridge/bitcoin-vault
or
yarn add @0xbridge/bitcoin-vault
Below are examples demonstrating common use cases.
import { TransactionService } from '@0xbridge/bitcoin-vault';
// Variables (example values)
const userAddress = 'tb1qsomeTestnetAddr...';
const userWif = 'cYourPrivateKey...';
const lockingAddress = 'tb1qLockingAddress...';
const lockingAmount = 10_000; // Satoshis
const oxbridgeAmount = 5_000; // Satoshis
const txService = new TransactionService();
(async () => {
try {
// define metadata to embed in OP_RETURN
const metadataParams = {
receiverAddress: '0xSomeReceiverOnAnotherChain',
lockedAmount: 1000,
chainId: 5,
baseTokenAmount: 99999,
};
// Fee rate can be omitted to automatically fetch a recommended rate
const feeRate = 5; // sat/vB
const { txid, rawTxHex } = await txService.createAndSignTransaction(
userAddress,
userWif,
lockingAddress,
lockingAmount,
oxbridgeAmount,
metadataParams,
feeRate
);
console.log('Transaction broadcast successfully!');
console.log('TXID:', txid);
console.log('Raw Transaction Hex:', rawTxHex);
} catch (err) {
console.error('Error creating or signing transaction:', err);
}
})();
import { TransactionService } from '@0xbridge/bitcoin-vault';
const userAddress = 'tb1qsomeTestnetAddr...';
const lockingAddress = 'tb1qLockingAddress...';
const lockingAmount = 10_000; // Satoshis
const oxbridgeAmount = 5_000; // Satoshis
(async () => {
try {
const txService = new TransactionService();
const { psbtBase64 } = await txService.createUnsignedTransaction(
userAddress,
Buffer.from('...someUserPubKey...'), // The user's public key
lockingAddress,
lockingAmount,
oxbridgeAmount,
{
receiverAddress: '0xSomeReceiverOnAnotherChain',
lockedAmount: 1000,
chainId: 5,
baseTokenAmount: 99999,
}
// feeRate: 5 (Optional)
);
console.log('Unsigned PSBT (Base64):', psbtBase64);
// Later, you or another party can sign the PSBT:
} catch (err) {
console.error('Error creating an unsigned transaction:', err);
}
})();
import {
createTaprootScriptWithMultisigAndTimelock,
createTaprootOutput,
generateRandomKeyPair
} from '@0xbridge/bitcoin-vault';
import * as bitcoin from 'bitcoinjs-lib';
// Create dummy key pairs for the user and AVS (vault) signers
const userKeyPair = generateRandomKeyPair();
const avsKeyPair = generateRandomKeyPair();
// Choose a locktime (block height or timestamp)
const locktime = 500_000;
const tapVault = createTaprootScriptWithMultisigAndTimelock(
userKeyPair.publicKey,
avsKeyPair.publicKey,
locktime
);
// Build a Taproot output (address) using the userKeyPair as the internal key
const taprootOutput = createTaprootOutput(
userKeyPair.publicKey,
tapVault,
bitcoin.networks.testnet
);
console.log('Generated Taproot Address:', taprootOutput.taprootAddress);
console.log('Taproot Output Script (hex):', taprootOutput.output?.toString('hex'));
import { fetchUtxos, fetchFeeRate, selectUtxos } from '@0xbridge/bitcoin-vault';
const apiConfig = {
primary: 'https://blockstream.info/testnet/api',
fallback: 'https://mempool.space/testnet/api',
};
(async () => {
try {
// Fetch unspent outputs for a given address
const utxos = await fetchUtxos(apiConfig, 'tb1qsomeTestnetAddr...');
console.log('Fetched UTXOs:', utxos);
// Fetch recommended fee rate (sat/vB)
const feeRate = await fetchFeeRate(apiConfig);
console.log('Recommended fee rate:', feeRate);
// Select UTXOs that sum up to at least `needed` satoshis
const needed = 20_000; // Satoshis
const { chosenUtxos, totalAmount } = selectUtxos(utxos, needed);
console.log('Selected UTXOs:', chosenUtxos);
console.log('Total Amount Found:', totalAmount);
} catch (err) {
console.error('Error fetching UTXOs or fee rate:', err);
}
})();
Once a PSBT is finalized (signed and finalizeAllInputs() called), you can broadcast with the built-in method:
import { TransactionService } from '@0xbridge/bitcoin-vault';
const txid = await txService.broadcastTransaction(txHex);
console.log('Broadcasted TxID:', txid);
FAQs
Bitcoin-psbt implementation TypeScript library supporting ESM and CJS.
We found that @0xbridge/bitcoin-vault demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.