BitGo JavaScript SDK

repository·master·Indexed 18 days ago

https://github.com/bitgo/bitgojs

A comprehensive suite of modules for building multi-signature cryptocurrency applications with integration for BitGo's co-signing services. Supports Bitcoin, Ethereum, Algorand, and Tezos. Features include wallet lifecycle management, transaction handling, webhook operations, BIP322 Proof of Address Ownership, and specialized chain operations such as Algorand account consolidation and Ethereum forwarder management. Available for use with TypeScript (recommended) and JavaScript.

Tokens
163.4K
Snippets
663
Records
1.1K
Agent score
64%

What's inside bitgojs

  1. Overview of BitGo key-card

    master
    The key-card module enables the generation of keycards immediately after creating BitGo wallets. Keycards serve as a recovery mechanism by storing the essential information required to recover wallet funds in scenarios where either the user or the BitGo key is lost.
  2. Overview of the BitGo JavaScript SDK modules

    master

    The BitGo SDK is a monorepo composed of several specialized modules. Depending on your use case (UTXO-based coins, account-based coins, or infrastructure), you will need to install and use specific packages.

    Key modules include:

    • bitgo: Core module for authentication, wallet management, and coin implementations.
    • @bitgo/account-lib: For building and signing transactions for account-based coins.
    • @bitgo/utxo-lib: For building and signing transactions for UTXO-based coins.
    • @bitgo/express: A local BitGo transaction signing server and proxy.
    • @bitgo/blockapis: Access to public block explorer APIs.
    • @bitgo/statics: Static configuration values used across the platform.
  3. What is BitGo Express?

    master

    BitGo Express is a local signing server that provides a REST API. It is designed for developers working in languages without an official BitGo SDK.

    It runs as a service in your own datacenter and handles client-side operations involving your own keys (such as partially signing transactions) before they are submitted to BitGo. This ensures your private keys never leave your network. Additionally, BitGo Express can proxy standard BitGo REST APIs, providing a unified interface through a single REST API.

  4. Features of BitGo abstract-utxo

    master

    The abstract-utxo module provides several core capabilities for UTXO-based asset management:

    Transaction Operations

    • Building & Signing: Supports legacy and PSBT (Partially Signed Bitcoin Transaction) formats.
    • Multi-signature: Supports 2-of-3 multisig with various script types including P2SH, P2WSH, P2SH-P2WSH, and P2TR-MuSig2.
    • Verification: Allows for comprehensive transaction intent verification before signing.
    • Explanation: Capability to decode and explain transaction details such as inputs, outputs, and fees.

    Wallet Types

    • Fixed Script Wallets: Traditional HD wallets with deterministic address generation.
    • Descriptor Wallets: Modern wallet format using output script descriptors.
    • Distributed Custody: Support for enterprise custody configurations.

    Address Management

    • Address validation and derivation verification.
    • Support for multiple formats: base58, bech32, and cashaddr (for BCH).
    • Chain/index-based address generation for fixed script wallets.

    Recovery Operations

    • Backup Key Recovery: Recover funds using a backup key if BitGo is unavailable.
    • Cross-Chain Recovery: Recover coins sent to the wrong chain (e.g., BTC sent to an LTC address).
    • V1 Wallet Recovery: Support for legacy V1 wallet recovery.

    Advanced Features

    • BIP322 message signing.
    • MuSig2 for Taproot multisig.
    • Replay protection for chain splits.
    • Custom change address handling.
    • RBF (Replace-by-Fee) transaction support.
  5. Understand the Account Lib project structure

    master

    The library is organized by coin ticker symbols to separate core logic from blockchain-specific implementations:

    • Base Classes: Core interfaces for TransactionBuilder and Transaction are located in src/coin/baseCoin.
    • Coin Implementations: The actual signing, validation, and encoding logic for specific blockchains resides in src/coin/<coin-ticker>/ (e.g., src/coin/trx for Tron).
    • Tests: Unit tests are located in test, with coin-specific tests organized under test/unit/coin/<coin-ticker>/<coin-ticker>.js.
    • External Resources: Small snippets of required upstream code that are not pulled in as full dependencies are stored in resources/.
  6. Use @bitgo/sdk-coin-evm for EVM asset integration

    master
    The @bitgo/sdk-coin-evm module provides a configurable common implementation for EVM (Ethereum Virtual Machine) assets. It is designed to reduce boilerplate when integrating new EVM-based coins by leveraging @bitgo/abstract-eth as its foundation.
  7. Use @bitgo/sdk-coin-cosmos for Cosmos SDK chains

    master
    @bitgo/sdk-coin-cosmos is a configurable common module designed for Cosmos SDK chains. It leverages @bitgo/abstract-cosmos to minimize the boilerplate required when integrating new Cosmos-based coins. Instead of requiring a unique module for every individual coin, this module allows developers to add support for new Cosmos chains via configuration in the statics package.
  8. Estimate Bitcoin transaction vSize with Dimensions

    master

    The Dimensions class is used to calculate an accurate estimate of a transaction's virtual size (vSize), which is critical for determining proper transaction fees. You can instantiate Dimensions using raw attributes or use static factory methods to derive dimensions from unspent outputs, inputs, or outputs.

    import { Dimensions } from '@bitgo/unspents';
    
    // Using raw attributes
    const dims = new Dimensions({
      nP2shInputs: 1,
      nP2shP2wshInputs: 1,
      nP2wshInputs: 1,
      outputs: { count: 1, size: 32 },
    });
    
    // Estimating vSize by combining dimensions
    const vSize = Dimensions.fromUnspents({ unspents: myUnspents })
      .plus(Dimensions.fromOutputOnChain(Codes.p2shP2wsh.internal).times(nOutputs))
      .getVSize();
  9. Understand the role of Resources in @bitgo/account-lib

    master
    In @bitgo/account-lib, the resources directory contains external logic necessary for handling signing, validation, and address derivation for specific coins. These resources are often extracted snippets from larger codebases that the library requires to perform coin-specific operations without importing the entire external codebase.