Skip to content

unisat-wallet/fb-farming-tools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FB Farming - Staking Tools

🎯 Overview

FB Farming Tools is a completely open-source toolkit for Fractal Bitcoin non-custodial staking. This project demonstrates the technical implementation behind FB Farming's staking system, proving it is truly non-custodial by providing users with direct access to the staking address generation rules and emergency withdrawal tools.

Key Components:

  • Staking Address Generation: Transparent algorithm using Taproot technology
  • Emergency Withdrawal Tool: Independent recovery mechanism that works even if the main platform is unavailable
  • Complete Source Code: All staking logic is open and verifiable

πŸ”’ Security Features

Core Security Guarantees

  • βœ… Fully Non-custodial: Uses Taproot technology where only user private keys can unlock funds
  • βœ… No Backdoors: Uses BIP-341 standard provably unspendable internal pubkey
  • βœ… Open Source Transparency: All source code is public and independently verifiable
  • βœ… Emergency Withdrawal: Users can withdraw funds independently even if website fails

Staking Address Generation Rules

The FB Farming staking system uses a deterministic address generation algorithm that ensures complete user control:

1. Taproot Address Structure

Staking Address = P2TR(internal_pubkey, script_tree)

Where:
- internal_pubkey = 50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0
- script_tree = { version: 192, script: [user_pubkey, OP_CHECKSIG] }

2. Security Properties

  • Internal Pubkey: Uses BIP-341 standard provably unspendable pubkey
  • Leaf Script: Simple [User_Pubkey] OP_CHECKSIG - only user can sign
  • Deterministic: Same user pubkey always generates same staking address
  • No Backdoors: Internal pubkey has no known private key

3. Manual Recovery Process

Users can always recover funds independently:

  1. Generate Address: Use your wallet's public key with the generation algorithm
  2. Find UTXOs: Query blockchain for unspent outputs at your staking address
  3. Create Transaction: Build unstaking transaction sending funds to your address
  4. Sign & Broadcast: Sign with your private key and broadcast to network

This process requires NO permission from any third party.

πŸš€ Quick Start

Requirements

  • Node.js >= 14.0.0
  • Yarn or npm
  • Unisat Wallet browser extension

Installation

# Clone repository
git clone https://github.com/your-org/fb-farming-tools
cd fb-farming-tools

# Install dependencies
yarn install

# Install web dependencies
cd web
yarn install

Running

# Start frontend application
yarn start:web

# Or from root directory
cd web && yarn start

πŸ“± Features

1. Stake Address Generator

  • Input user pubkey to generate corresponding stake address
  • Real-time address security verification
  • Display script structure and technical details
  • Automatically fetch address balance

2. Security Verification Tool

  • Verify stake address can only be unlocked by user private key
  • Display Taproot script structure
  • Prove internal pubkey is unspendable
  • Provide complete security analysis

3. Emergency Withdrawal Tool

  • Web Interface: User-friendly emergency withdrawal application
  • Automatic Address Generation: Derives staking address from user's wallet
  • Complete UTXO Recovery: Withdraws all available staked funds
  • Offline Capable: Can work without internet (except for balance checking)
  • Independent Operation: Functions completely separate from main platform
  • PSBT Support: Generates Partially Signed Bitcoin Transactions for wallet signing

4. Source Code Display

  • Complete display of core algorithm source code
  • Detailed security explanations
  • Technical principle explanations
  • Independent verification guide

πŸ› οΈ Project Structure

fb-farming-tools/
β”œβ”€β”€ lib/                    # Core staking library
β”‚   β”œβ”€β”€ constant.ts         # Taproot constants
β”‚   └── stake-utils.ts      # Address generation utilities
β”œβ”€β”€ src/                    # Unified export interface
β”‚   └── index.ts           # Main library exports
β”œβ”€β”€ web/                    # Emergency withdrawal web app
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.tsx        # Main React application
β”‚   β”‚   β”œβ”€β”€ lib/           # Frontend-specific utilities
β”‚   β”‚   β”‚   β”œβ”€β”€ constant.ts     # Frontend constants
β”‚   β”‚   β”‚   β”œβ”€β”€ stake-utils.ts  # Address generation
β”‚   β”‚   β”‚   └── tx-utils.ts     # Transaction creation
β”‚   β”‚   └── utils.ts       # Helper utilities
β”‚   β”œβ”€β”€ public/            # Static assets
β”‚   └── package.json       # Frontend dependencies
β”œβ”€β”€ package.json           # Main project config
└── README.md              # This documentation

πŸ“š API Documentation

Core Functions

getStakeAddress(params)

Generate staking address using the same algorithm as FB Farming

interface StakeAddressParams {
  pubkey: string; // User public key (hex format)
  networkType: NetworkType; // Network type (MAINNET)
}

const address = getStakeAddress({
  pubkey: "03e61e6043687e474d7b37f56e46ed24a9f5da845746c81eb0b4fe4b2d3d5a7950",
  networkType: NetworkType.MAINNET,
});

// Returns: "bc1p..." (Taproot address)
// This address will match exactly what FB Farming generates

buildStakePayment(params)

Build Taproot payment for stake address (low-level function)

const payment = buildStakePayment(
  internalPubkey, // BIP-341 unspendable pubkey
  leafPubkey, // User's public key
  psbtNetwork // Bitcoin network
);

// Returns payment object with address, scripts, and control blocks

πŸ”§ Development Guide

Local Development

# Build core library
yarn build

# Run tests
yarn test

# Start frontend dev server
yarn start:web

Production Build

# Build library
yarn build:lib

# Build frontend
yarn build:web

πŸ” Security Verification

How to Verify System Security

  1. Review Source Code:

    • All core logic is in lib/ directory
    • Key files: lib/stake-utils.ts, web/src/lib/tx-utils.ts
  2. Verify Internal Pubkey:

    # Confirm using BIP-341 standard unspendable pubkey
    echo "50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0"
  3. Test Address Generation:

    // Generate address with your pubkey
    const address = getStakeAddress({
      pubkey: "your_pubkey_here",
      networkType: NetworkType.MAINNET,
    });
    // Verify generated address matches official system
  4. Test Unlock Function:

    • Use small amounts for testing
    • Verify only your private key can unlock
    • Confirm no other unlock paths exist

Security Audit

  • Internal pubkey source: BIP-341 Standard
  • Script type: Pay-to-Taproot (P2TR)
  • Unlock condition: User private key signature only

πŸ“– Usage Scenarios

Emergency Withdrawal via Web Interface

When to use: The main FB Farming website is down or inaccessible, but you need to withdraw your staked funds.

  1. Access Emergency Tool:

    cd web
    yarn install
    yarn start

    Navigate to http://localhost:3000

  2. Connect Wallet:

    • Install and unlock Unisat Wallet
    • Connect to the emergency withdrawal tool
    • Switch to Fractal Bitcoin network
  3. Automatic Recovery:

    • Tool automatically generates your staking address
    • Fetches your current staked balance
    • Shows all available UTXOs for withdrawal
  4. Execute Withdrawal:

    • Review the emergency withdrawal warning
    • Set transaction fee rate
    • Sign and broadcast the withdrawal transaction
    • Note: This forfeits any pending staking rewards

Manual Recovery via Code

When to use: You want to implement your own recovery tool or understand the technical details.

// 1. Generate your staking address
const stakeAddress = getStakeAddress({
  pubkey: "your_wallet_pubkey",
  networkType: NetworkType.MAINNET,
});

// 2. Find your UTXOs
const utxos = await getAddressUtxos(stakeAddress);

// 3. Use the web emergency tool or build your own transaction
// The emergency withdrawal tool shows how to create unstaking transactions

// 4. For implementation details, see:
// - web/src/lib/tx-utils.ts: createUnstakeTx() function
// - lib/stake-utils.ts: buildStakePayment() and getStakeAddress()
// - web/src/App.tsx: Complete emergency withdrawal implementation

Command Line Usage

# Run address generation example
yarn run:example

# Execute tests
ts-node test/createLockAddresses.ts

❓ FAQ

Q: How to ensure fund security?

A: This system uses Taproot technology with unspendable internal pubkey, mathematically guaranteeing only user private keys can unlock funds. We cannot access user funds.

Q: What if the FB Farming website shuts down?

A: You have multiple independent recovery options:

  1. Web Emergency Tool: Use the included React application for guided withdrawal
  2. Direct Code Usage: Use the TypeScript libraries to build your own withdrawal tool
  3. Manual Construction: Use any Bitcoin library to create the withdrawal transaction
  4. Community Tools: Other developers can build compatible tools using the open-source specification

All methods work completely independently of any centralized service.

Q: How to verify the staking system has no backdoors?

A: Complete Verification Process:

  1. Review Address Generation:

    // Check lib/constant.ts
    const TAPROOT_ONLY_SCRIPT_PUBKEY =
      "50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0";
  2. Verify Internal Pubkey:

  3. Inspect Script Tree:

    // Only unlock condition is user signature
    const lockScript = [toXOnly(user_pubkey), bitcoin.opcodes.OP_CHECKSIG];
  4. Test Address Generation:

    • Generate address with your pubkey
    • Verify it matches FB Farming's generated address
    • Confirms same algorithm is used
  5. Verify No Alternative Unlock Paths:

    • Script tree contains only one leaf (user signature)
    • Internal pubkey cannot be used to spend
    • No time locks, multisig, or other conditions

Q: Which networks are supported?

A: Currently supports Fractal Bitcoin mainnet. Other networks can be supported by modifying NetworkType.

🀝 Contributing

  1. Fork this repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

πŸ“„ License

This project is licensed under the MIT License - see LICENSE file for details.

⚠️ Disclaimer

  • This tool is for educational and demonstration purposes only
  • Please conduct thorough testing before use
  • Cryptocurrency investment involves risks, please operate cautiously
  • We are not responsible for any fund losses

πŸ”— Related Links


Remember: Your keys, your coins. This is true non-custodial. πŸ”

About

FB Farming Tools is a completely open-source toolkit for Fractal Bitcoin non-custodial staking.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published